Skip to content

Instantly share code, notes, and snippets.

@ninyawee
Created July 31, 2025 06:23
Show Gist options
  • Save ninyawee/0f4cfabdc521ed396b20fd4644f3a52b to your computer and use it in GitHub Desktop.
Save ninyawee/0f4cfabdc521ed396b20fd4644f3a52b to your computer and use it in GitHub Desktop.
ClickHouse.com User-Agent Based Content Serving Explanation

ClickHouse.com User-Agent Based Content Serving

The ClickHouse website (https://clickhouse.com/) serves different content based on the User-Agent header in the HTTP request.

How it Works

For Command-Line Tools (Default curl/wget)

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

For Web Browsers

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">...

Technical Details

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

Response Headers

The content type also changes:

  • Shell script: content-type: text/plain; charset=utf-8
  • HTML page: content-type: text/html; charset=utf-8 (implied)

Why This Pattern?

This clever content negotiation technique serves two purposes:

  1. Developer Convenience: Allows the memorable one-liner curl https://clickhouse.com/ | sh for installation
  2. User Experience: Regular web visitors get the website when visiting via browser

Similar Examples

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)"

Testing It Yourself

Get the installation script:

curl https://clickhouse.com/

Get the website HTML:

curl https://clickhouse.com/ -H 'User-Agent: Mozilla/5.0'

Check headers only:

curl -I https://clickhouse.com/
curl -I https://clickhouse.com/ -H 'User-Agent: Mozilla/5.0'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment