The ClickHouse website (https://clickhouse.com/) serves different content based on the User-Agent header in the HTTP request.
When accessed with command-line tools like curl
or wget
, the server returns a shell installation script:
curl https://clickhouse.com/
Returns:
#!/bin/sh -e
OS=$(uname -s)
ARCH=$(uname -m)
...
This allows for the convenient one-liner installation:
curl https://clickhouse.com/ | sh
When accessed with a browser User-Agent, the server returns the actual HTML website:
curl https://clickhouse.com/ \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36'
Returns:
<!DOCTYPE html><html lang="en" class="light scroll-smooth">...
The server examines the User-Agent header and makes a decision:
- Command-line User-Agents (e.g.,
curl/7.x.x
,wget/1.x
): Get the shell script - Browser User-Agents (containing "Mozilla", "Chrome", etc.): Get the HTML website
The content type also changes:
- Shell script:
content-type: text/plain; charset=utf-8
- HTML page:
content-type: text/html; charset=utf-8
(implied)
This clever content negotiation technique serves two purposes:
- Developer Convenience: Allows the memorable one-liner
curl https://clickhouse.com/ | sh
for installation - User Experience: Regular web visitors get the website when visiting via browser
Other projects using similar patterns:
- Rust:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
curl https://clickhouse.com/
curl https://clickhouse.com/ -H 'User-Agent: Mozilla/5.0'
curl -I https://clickhouse.com/
curl -I https://clickhouse.com/ -H 'User-Agent: Mozilla/5.0'