Sub topic 11
HTTP/1.1, HTTP/2 and HTTP/3 compared
This chapter assumes you have read the chapters on TCP, TLS and the HTTP request and response. You should know that a request has a method, path and headers, and that a response has a status code, headers and a body. Here you will see how the protocol versions carry those same messages in different ways.
Same meaning, different transport
All three versions keep the same semantics: methods, status codes, headers and bodies. A GET returning 200 OK means the same thing in each. What changes is how the messages are encoded and how they travel over the network.
HTTP/1.1: text over TCP
HTTP/1.1 sends human-readable text, as in the request you saw earlier. A connection stays open for reuse (Connection: keep-alive). Even so, responses on one connection must come back in order. If a large response is slow, the ones behind it wait. This is called head-of-line blocking at the HTTP level.
Browsers work around it by opening several connections to the same host, typically six. Each extra connection costs its own TCP and TLS setup.
HTTP/2: multiplexing over one TCP connection
HTTP/2 replaces the text format with binary frames. Each request and response is a stream, and frames from many streams are interleaved on a single connection. A slow response no longer blocks the others.
- Multiplexing: many requests share one connection, so the browser does not need six.
- Header compression (HPACK): repeated headers such as
User-Agentand cookies are sent as short references. - Negotiation: the client and server agree on HTTP/2 during the TLS handshake, using the ALPN extension. No extra round trip is needed.
HTTP/2 still runs on TCP. TCP delivers bytes in order, so one lost packet stalls every stream until it is retransmitted. This is head-of-line blocking at the transport level.
HTTP/3: streams over QUIC
HTTP/3 runs on QUIC, a transport built on UDP. QUIC provides reliable delivery, encryption (it embeds TLS 1.3) and streams. Loss on one stream delays only that stream. QUIC also combines the transport and TLS handshakes, so a new connection typically takes one round trip instead of two or more. Connections are identified by an ID instead of an address and port pair, so they can survive a switch from Wi-Fi to mobile data.
A browser usually does not know in advance that a server supports HTTP/3. The server announces it in an Alt-Svc response header, or in a DNS HTTPS record. The first visit often uses HTTP/2, and later requests move to HTTP/3. If UDP is blocked on the network, the browser falls back to HTTP/2.
Side-by-side summary
| Feature | HTTP/1.1 | HTTP/2 | HTTP/3 |
|---|---|---|---|
| Message format | Text | Binary frames | Binary frames |
| Transport | TCP | TCP | QUIC over UDP |
| Requests per connection at once | One | Many (multiplexed) | Many (multiplexed) |
| Header compression | None | HPACK | QPACK |
| Blocked by one lost packet | The connection | All streams | One stream |
| Encryption | Optional (HTTPS) | Required by browsers | Always |
Checking the version
curl can force a version and print the one that was used.
curl --http1.1 -s -o /dev/null -w '%{http_version}\n' https://example.com/
curl --http2 -s -o /dev/null -w '%{http_version}\n' https://example.com/The first command prints 1.1. The second prints 2 if the server supports it. The --http3 option works only if your curl was built with HTTP/3 support. In the browser, open the Network panel and enable the Protocol column. It shows http/1.1, h2 or h3 for each request.
Exercise
A page loads 40 small files over HTTP/2 on a network that drops a few packets. Why can this still be slower than expected, and which version addresses the cause?
Show answer
HTTP/2 multiplexes all 40 streams over one TCP connection. TCP delivers bytes in order, so a single lost packet stalls every stream until it is retransmitted. HTTP/3 runs on QUIC, where streams are independent, so the loss delays only the stream it affected.