HTTP/1.1, HTTP/2 and HTTP/3 Deep Dive

Methods, headers, status codes, keep-alive, chunked encoding, multiplexing, QUIC — the protocol backend developers debug every day.

BeginnerUpdated 2026-10-2958K views

The request/response grammar

HTTP is a plain-text, stateless, request-response protocol. A request is: method, path, version, headers, blank line, optional body. A response mirrors it: version, status, headers, blank line, body.

GET /api/orders?limit=20 HTTP/1.1      ← 请求行
Host: api.example.com                    ← HTTP/1.1 唯一必填头
Authorization: Bearer eyJhbGciOi...
Accept: application/json
                                         ← 空行(没有 body 也必须有)

HTTP/1.1 200 OK                          ← 状态行
Content-Type: application/json
Content-Length: 128                       ← 或 Transfer-Encoding: chunked
                                         ← 空行
{"orders": []}                            ← 正文
CategoryCodesMeaning for the backend dev
1xx 信息化100 ContinuePOST 大 body 前先问「要不要我发」
2xx 成功200 / 201 / 204OK / 新建成功 / 成功但无正文
3xx 重定向301 / 302 / 304永久跳转 / 临时跳转 / 缓存仍然有效
4xx 客户端错400 / 401 / 403 / 409 / 429参数错 / 未认证 / 无权限 / 冲突 / 限流
5xx 服务端错500 / 502 / 503 / 504内部错误 / 网关错误 / 服务不可用 / 网关超时
Distinguish 401 vs 403 vs 400 precisely: 401 = 'who are you?', 403 = 'I know you but you can't', 400 = 'your payload is nonsense'. Frontends and API clients switch on these codes.

HTTP/1.1: keep-alive, pipelining and its ceiling

HTTP/1.1 keeps the TCP connection open (keep-alive) so subsequent requests reuse it — huge win over 1.0's reconnect-every-time. But requests on one connection are serialized; browsers work around it by opening 6 parallel connections per host.

# 大响应分块流式发送(不知道总长时用)
HTTP/1.1 200 OK
Transfer-Encoding: chunked

7\r\n                ← 这个块的字节数(hex)
hello, \r\n
9\r\n
backend! \r\n
0\r\n                ← 长度 0 = 结束
\r\n
  • Head-of-line blocking at the HTTP level: request 2 waits for request 1 on the same connection
  • Domain sharding (static.example.com) was a hack to get more parallel connections — obsolete with HTTP/2
  • Content-Length when you know it, chunked when you don't (streaming, SSE, generated responses)

HTTP/2 and HTTP/3: multiplexing and QUIC

FeatureHTTP/1.1HTTP/2HTTP/3
传输层TCP + TLSTCP + TLSQUIC(UDP)
二进制分帧无有有
多路复用无(每连接串行)一个连接并发 N 个流同 HTTP/2
队头阻塞HTTP 层 + TCP 层解决 HTTP 层,仍留 TCP 层两个都解决
Server Push无有(实践中已基本弃用)弃用
连接建立1-3 RTT1-2 RTT0-1 RTT(首包更快)
连接迁移不可能不可能可以(IP 变了连接不断)
HTTP/2 did NOT remove head-of-line blocking — it just moved it from the HTTP layer to the TCP layer: one lost packet stalls ALL streams over that connection. QUIC's per-stream ACK/retry is exactly the fix for that.

Enable HTTP/2 by simply using https with a modern Nginx (listen 443 ssl http2;). HTTP/3 needs UDP/443 open in the firewall + QUIC-capable server (Nginx 1.25+, Caddy, Cloudflare free tier).

Friends & Partners