Skip to content
Sign inGet all access
Chapter 12·8 minFree

HTTP/2 and HTTP/3

The same semantics, different bytes — and what to actually do.

Methods, status codes and headers are unchanged. Only the bytes differ.

What stayed the same

One URL, either version, same status:

terminal
curl -sk --http2 -o /dev/null -w 'http2 -> %{http_version}\n' \
  https://localhost:8443/
curl -sk --http1.1 -o /dev/null -w 'http1.1 -> %{http_version}\n' \
  https://localhost:8443/
Outputhttp2 -> 2http1.1 -> 1.1

Chapters 3 to 9 still apply unchanged.

Binary framing

HTTP/1.1 was text you could type. This is not:

terminal
curl -skv --http2 https://localhost:8443/ -o /dev/null 2>&1 \
  | grep 'OPENED stream'
Output* [HTTP/2] [1] OPENED stream for https://localhost:8443/

Lowercase headers

The wire format normalises header names:

terminal
curl -skv --http2 https://localhost:8443/ -o /dev/null 2>&1 \
  | grep -E '^< (HTTP|server|content)'
Output< HTTP/2 200 < server: nginx/1.27.5< content-type: text/plain< content-length: 7

Without the < markers:

terminal
curl -skI --http2 https://localhost:8443/ | head -2
OutputHTTP/2 200 server: nginx/1.27.5

Two differences from chapter 2: names arrive lowercase, and the status line has no reason phrase. Side by side:

terminal
curl -skv --http1.1 https://localhost:8443/ -o /dev/null 2>&1 | grep '^< HTTP'
curl -skv --http2 https://localhost:8443/ -o /dev/null 2>&1 | grep '^< HTTP'
Output< HTTP/1.1 200 OK< HTTP/2 200

Streams

Each request is a numbered stream; many share one connection:

terminal
curl -skv --http2 https://localhost:8443/ https://localhost:8443/ \
  -o /dev/null -o /dev/null 2>&1 | grep -c 'OPENED stream'
Output2

curl counts one connection for both:

terminal
curl -sk --http2 -o /dev/null -o /dev/null \
  -w 'connects=%{num_connects}\n' \
  https://localhost:8443/ https://localhost:8443/
Outputconnects=1connects=0

Two streams, one connection, no ordering between them — the fix for chapter 7’s head-of-line blocking.

The six-connection workaround becomes unnecessary, and so does bundling to dodge it.

Negotiating it

ALPN picks the version inside the TLS handshake — chapter 10:

terminal
curl -skv --http2 https://localhost:8443/ -o /dev/null 2>&1 \
  | grep -E 'ALPN|using HTTP'
Output* ALPN: curl offers h2,http/1.1* ALPN: server accepted h2* using HTTP/2

HPACK

Headers compress against a table both sides keep, so a repeated one costs almost nothing. A large cookie stops being expensive.

It is per-connection state, which made HTTP/2 implementations a source of memory-exhaustion bugs.

Server push

The server could send a response nobody asked for. Chrome removed it in 2022 and the others followed.

It lost to <link rel="preload">, which lets the client decide. Push in a tutorial means the tutorial predates 2022.

HTTP/3 and QUIC

Same semantics again, over UDP. This curl cannot speak it:

terminal
curl --http3 https://example.com/ 2>&1 | head -1
Outputcurl: option --http3: the installed libcurl version doesn't support this

The macOS build ships without QUIC, so this section has no transcript.

TCP recovers lost packets in order, so one loss stalls every stream — head-of-line blocking moved down a layer rather than vanishing. QUIC makes each stream independent.

A server advertises it in a header:

terminal
{ printf 'HTTP/1.1 200 OK\r\n'
  printf 'Alt-Svc: h3=":443"; ma=86400\r\n'
  printf 'Content-Length: 0\r\n\r\n'
} | nc -l 9000 >/dev/null &
curl -sI localhost:9000/ | grep -i alt-svc
OutputAlt-Svc: h3=":443"; ma=86400

Alt-Svc tells the client to try HTTP/3 next time.

What to actually do

Almost nothing. Turn it on at the edge, change no application code:

Practice Under HTTP/2
Bundling every asset mostly unnecessary
Domain sharding actively harmful — it splits the connection
Inlining images as data URIs unnecessary
Six-connection workarounds obsolete