读书笔记 · 约 12,121 字 · 预计推送 2 部分

2026-11-04 · 主题精读:HTTP 演进 —— HTTP/1.1、HTTP/2、HTTP/3 与 QUIC 未开始

目录

题记与说明


来源清单

#来源链接阅读方式定位
1MDN《Evolution of HTTP》(2025-03-14 更新)https://developer.mozilla.org/en-US/docs/Web/HTTP/Evolution_of_HTTPweb_reader 全文抓取权威通史:0.9→1.0→1.1→2→3 时间线与官方数据
2Robin Marx《Head-of-Line Blocking in QUIC and HTTP/3: The Details》(GitHub living document)https://github.com/rmarx/holblocking-blogpostweb_reader 全文抓取(raw README)深度机制分析:HOL blocking 四种变体 + 实际收益质疑
3RFC 9114《HTTP/3》(IETF Standards Track, 2022-06, M. Bishop 主编)https://www.rfc-editor.org/rfc/rfc9114.txtweb_reader 全文抓取协议原文规范:连接建立、帧、QPACK、与 HTTP/2 差异附录
4Cloudflare Learning Center《What is HTTP/3?》https://www.cloudflare.com/learning/performance/what-is-http3/web_reader 全文抓取产业视角:QUIC 的安全、移动性与 0-RTT 叙述
5Daniel Stenberg《HTTP/3 explained》- HTTP/3 章https://http3-explained.haxx.se/en/h3web_reader 全文抓取(该页较短)HTTP over QUIC 需要改哪些东西的简明权威说明
6W3Techs《Usage statistics of HTTP/3 for websites》(2026-11)https://w3techs.com/technologies/details/ce-http3搜索引擎摘要交叉验证(两次一致),未直接抓到原页采用率数据
7TechnologyChecker《HTTP Protocol Adoption Q3 2026》https://technologychecker.io/blog/http-protocol-adoption同上(经搜索摘要转引)"支持率 ≠ 实际流量"的反差数据

注:Cloudflare 旧的 learning/web/what-is-http3 与 learning/network-layer/what-is-QUIC 两个 URL 本次实测 404,正确页面已迁移至 learning/performance/what-is-http3。


1. 核心问题

Web 页面从最初的几个 HTML 文件膨胀到一次加载动辄上百个资源(JS/CSS/图片/字体),HTTP 的语义(请求/响应、方法、状态码、缓存)三十年来基本不变,但承载方式经历了三次大改。整个演进史要解决的核心问题只有一个反复变奏的主题:

队头阻塞(Head-of-Line blocking, HOL)——Marx 给出的定义:"When a single (slow) object prevents other/following objects from making progress"(一个慢对象阻止其他/后面的对象前进)。

围绕它还叠加了三个次级问题:

  1. 连接开销:为绕过 HOL 而开 6 条 TCP 连接 + 域名分片,握手与服务器内存成本高;
  2. 握手延迟:TCP + TLS 各自握手的 RTT 累积,移动网络尤其痛;
  3. 安全滞后:明文 TCP 上跑 HTTP,加密是应用层事后补丁。

MDN 对演进驱动力的概括:"Over the years, web pages became more complex. Some of them were even applications in their own right. … Much more data was transmitted over significantly more HTTP requests and this created more complexity and overhead for HTTP/1.1 connections."

2. 主要主张

  1. 语义稳定,传输换代:HTTP/3 "supports the same semantics over a new transport protocol: QUIC"(RFC 9114 §1)。每一代 HTTP 改的不是"HTTP 是什么",而是"HTTP 的比特怎么上线"。Stenberg:"What primarily changes with HTTP/3 is how the bits get sent over to the other side of the communication."
  2. HTTP/2 只解决了一半 HOL:二进制分帧让应用层能多路复用,但 TCP 只看到一个字节流——丢一个包,所有 stream 一起停。RFC 9114 §1.1 的官方表述:"because the parallel nature of HTTP/2's multiplexing is not visible to TCP's loss recovery mechanisms, a lost or reordered packet causes all active transactions to experience a stall regardless of whether that transaction was directly impacted by the lost packet."
  3. HTTP/3 的解法是把"流"概念下沉到传输层:QUIC 的 STREAM 帧携带 per-stream 字节区间,丢包只冻结所属流。"Streams are independent of each other, so one stream that is blocked or suffers packet loss does not prevent progress on other streams."(RFC 9114 §2)
  4. 但 Marx 泼冷水:HOL 消除的实际收益可能有限。QUIC 在单流内仍保留顺序(文件必须按序重组);浏览器希望核心资源顺序发送(JS/CSS 要收完才能执行),而 HOL 消除要求资源交错发送——两个优化目标直接冲突。他的结论:"QUIC and HTTP/3's HOL blocking removal probably won't do all that much for Web performance in the majority of the cases." 他认为真正的收益来自 0-RTT 连接建立:"especially 0-RTT will provide the most Web performance benefits."
  5. HTTP/2 的部署现实:MDN 记录其"使用率在 2022 年 1 月达峰值 46.9%"后回落(被 HTTP/3 侵蚀);快速普及的原因是"网站和应用无需任何改动"。
  6. HTTP/3/QUIC 附带一揽子传输层升级:握手合并(crypto+transport 一次完成)、0-RTT、强制加密(连包头元数据都加密)、连接迁移(换 WiFi 不掉线)、每连接流控(防 Rapid Reset DDoS)。

3. 方法:每一代到底改了什么(技术路线精读)

3.1 HTTP/1.1(1997, RFC 2068):文本协议的原罪与"6 连接补丁"

MDN 列出的 HTTP/1.1 增量:连接复用(keep-alive)、pipelining、chunked 响应、缓存控制、内容协商、Host 头支持虚拟主机。但它有一个结构性缺陷:纯文本协议只在 payload 前面附加头部,无法区分一段字节属于哪个资源。

Marx 用图 3 演示了强行交错发送的后果:浏览器按 Content-Length: 1000 读 script.js,收到 450 字节后开始读到 style.css 的头部——直接把 CSS 的头和内容当成了 JS 的一部分,JS 解析器拿到的是:

function first() { return "hello"; }
HTTP/1.1 200 OK
Content-Length: 600

.h1 { font-size: 4em; }
func

结论:HTTP/1.1 单连接上响应必须完整传完才能换下一个资源(11112222 串行模式)。浏览器的补丁是每域名开 6 条并行 TCP 连接,再叠加域名分片(img.mysite.com、static.mysite.com…),一页最多 30 来条连接——"This works, but has considerable overhead"(TLS 握手、服务器状态与内存)。

Marx 在 bonus 章节澄清了一个常见误解:pipelining 只解决请求侧的 HOL——HTTP/1.1 规范要求响应必须按请求顺序返回("A server MUST send its responses to those [pipelined] requests in the same order that the requests were received"),"pipelining solves HOL blocking for requests, but not for responses",而且现代浏览器干脆不用它(无法中途取消、猜错队列更糟)。

3.2 HTTP/2(2015, RFC 7540/9113):二进制分帧,但 TCP 不知道

Google SPDY(2010 年代初)→ IETF HTTP/2(2015-05 标准化,MDN)。三个本质变化(MDN):

机制:每个 chunk 前面加帧(DATA/HEADERS 等),帧携带 stream id + 长度。浏览器据此把交错字节"解复用"回各资源流。响应调度自由度大增:公平交错 12121212、加权 221221221、倒序 22221111、部分发送(中途夭折低优先级流)——由优先级系统驱动。

但是:TCP 不知道自己在运 HTTP/2。TCP 只按字节区间重组一条流——丢包 2 但收到包 3 时,TCP 必须扣住包 3 等重传,即使包 3 里全是 stream 1 的数据、与丢的 stream 2 无关。Marx 总结四条链条:

- HTTP/1.1 had HOL blocking because it needs to send its responses in full and cannot multiplex them
- HTTP/2 solves that by introducing "frames" that indicate to which "stream" each resource chunk belongs
- TCP however does not know about these individual "streams" and just sees everything as 1 big stream
- If a TCP packet is lost, all later packets need to wait for its retransmission… TCP has Transport Layer HOL blocking.

Marx 同时给了定量的缓释:丢包率在高速有线网络约 0.01%,最差蜂窝网络也"很少高于 2%",且丢包成簇(路由器缓冲溢出)——所以 TCP 层 HOL 远不如 HTTP/1.1 层 HOL 频繁。还有拥塞控制的反直觉账:单条 HTTP/2 连接初始窗口约 14KB,而 HTTP/1.1 的 6 条连接各 14KB ≈ 84KB;HTTP/2 单连接一条流丢包就减速,HTTP/1.1 五条连接照常增长。所以现实中"HTTP/2 as it is currently deployed in browsers and servers is typically as fast or slightly faster than HTTP/1.1 in most conditions",而在高丢包慢网络下 HTTP/1.1 六连接甚至可能反超——这正是 QUIC 立项的动机。

3.3 HTTP/3 + QUIC(RFC 9000/9110-9114, 2021-2022):把流下沉到传输层

改 TCP 不可能(中间盒僵化、内核栈改动是十年尺度),于是 IETF 选择在 UDP 上重建一个"TCP 2.0"——QUIC(Marx: "In many ways, QUIC should be seen as a TCP 2.0. It includes the best versions all of TCP's features (reliability, Congestion Control, Flow Control, ordering, etc.)… QUIC also fully integrates TLS … and doesn't allow unencrypted connections.")。

关键动作(Marx 图 8-9):把 stream id 从 HTTP/2 的 DATA 帧挪进 QUIC 的 STREAM 帧,传输层逐流跟踪字节区间。丢包 2 时:stream 1 的包 3 数据字节区间连续、立即可交付;stream 2 有缺口、扣住等重传。"QUIC retains ordering within a single resource stream but no longer across individual streams"——单流内有序,跨流不再保证全序。

这个"跨流全序消失"直接引爆了三个 HTTP/3 的连锁重设计(RFC 9114 附录 A 是最权威的差异清单):

  1. HPACK → QPACK:"Because HPACK relies on in-order transmission of compressed field sections (a guarantee not provided by QUIC), HTTP/3 replaces HPACK with QPACK."(RFC 9114 §2)QPACK 用独立单向流维护动态表,编码块只引用表状态而不修改它,让编码者在压缩率与潜在 HOL 之间自选权衡(Stenberg 也强调这一点:"the header compression protocol used for HTTP/2 could not be used without it causing a head of block situation")。
  2. 优先级系统整个移除:"HTTP/2 specifies priority assignments in PRIORITY frames and (optionally) in HEADERS frames. HTTP/3 does not provide a means of signaling priority."(RFC 9114 附录 A.2.1)树形优先级操作依赖跨流有序,QUIC 上无法直接安全,后由独立的 Extensible Prioritization Scheme 草案(Marx 文中链接的 draft-ietf-httpbis-priority,即后来的 RFC 9218)另起炉灶。
  3. RST_STREAM/WINDOW_UPDATE/PING/CONTINUATION 等帧删除:流生命周期、流控、保活全部由 QUIC 接管(RFC 9114 附录 A.2.5 逐帧对照表);SETTINGS 只在控制流开头发一次,不再可变。

连接建立:ALPN token "h3";发现机制靠 Alt-Svc 头("Alt-Svc: h3=":50781"");QUIC 内嵌 TLS 1.3,"offering comparable confidentiality and integrity to running TLS over TCP, with the improved connection setup latency of TCP Fast Open"(RFC 9114 §1.2)。Cloudflare 补充:"QUIC combines the cryptographic and transport handshakes"以及 0-RTT:对连过的服务器"clients can skip the handshake requirement"。

移动性是 QUIC 的第二支柱(Cloudflare):"QUIC separates out the layer 4 transport connection from the layer 3 IP flow, allowing for migration between different networks without disruption"——WiFi 切蜂窝不断连;还用 credit-based stream 系统缓解 HTTP/2 Rapid Reset DDoS。回退路径在规范里写死:"Connectivity problems (e.g., blocking UDP) can result in a failure to establish a QUIC connection; clients SHOULD attempt to use TCP-based versions of HTTP in this case."(RFC 9114 §3.1)

3.4 一页对比表

维度HTTP/1.1HTTP/2HTTP/3 + QUIC
载体TCP(+ 可选 TLS)TCP + TLSQUIC over UDP,内嵌 TLS 1.3
编码文本二进制帧二进制帧(精简,无 stream id/flags)
多路复用✗(靠 6 连接+分片绕行)✓ 应用层帧✓ 传输层流(下沉)
应用层 HOL有(响应必须整发)无无
传输层 HOL有有(TCP 不识流)基本消除(单流内仍有)
头压缩无HPACK(依赖全序)QPACK(防 HOL 权衡)
优先级无显式PRIORITY 树(实践中常失灵)规范内移除,外部 RFC 9218
握手TCP+TLS 分离多次 RTT同左crypto+transport 合一;0-RTT 恢复
加密可选事实必选(浏览器要求)强制,包头元数据也加密
连接迁移✗✗✓(换网络不断连)
部署成本网站代码无需改无需改(关键于普及)无需改,但 UDP 可能被企业网封锁需回退

4. 数据与证据

证据是否充分:机制链条(分帧→流下沉→QPACK/优先级连锁)有 RFC 原文 + Marx 图解双重支撑,非常扎实;"HTTP/3 实际快多少"一问,本次精读未获得 2026 年的最新大规模实测数据(Marx 的量化判断是 2020 年前后早期实验 h3holblockingpaper 的推断,他自己声明"differently, it is a topic of my ongoing research");W3Techs 数字未直接核验原页,属搜索摘要转引。

5. 结论

  1. HTTP 演进 = 语义不动、承载重造。0.9→1.1 解决"能传什么",1.1→2 解决"应用层怎么排",2→3 解决"传输层怎么排"。
  2. HOL blocking 是贯穿三十年的主线:HTTP/1.1 应用层 HOL(靠 6 连接补丁)→ HTTP/2 应用层解决、TCP 层遗留 → HTTP/3 在传输层基本解决(单流内除外)。
  3. QUIC 不只是"UDP 上的 TCP":流感知 + 内嵌 TLS 1.3 + 握手合并 + 0-RTT + 连接迁移 + 强制加密,是传输层的整体重设计;HTTP/3 为此付出的代价是 QPACK 重写、优先级外置、大量帧被砍。
  4. 对性能要诚实:HOL 消除的理论收益受"顺序发送更利于资源加载"反向牵制,大概率只在高丢包网络兑现;多数场景下 HTTP/3 的真实增益更可能来自 0-RTT/1-RTT 快速握手与连接迁移。采用率(41% 站点支持 vs ~21% 实际流量)说明它已过临界点但远未完成替代。
  5. 部署侧几乎零成本(CDN/边缘节点开关即用),这解释了为什么协议换代能以"被动升级"方式完成。

6. 局限

来源自认的:

我推断的:

7. 对我的启发

  1. 个人站点/服务部署(Windows + CDN 场景):HTTP/3 是 CDN 上的一个开关,零代码改动——默认打开即可吃到 0-RTT 和移动网络收益,不要再为性能做域名分片(那是 HTTP/1.1 时代的补丁,在 2/3 下反而拆散了连接复用和拥塞窗口)。
  2. 排查网络问题时记得有"回退"这回事:企业网/防火墙封 UDP 443 会让 HTTP/3 静默失败,浏览器回退 HTTP/2——表现为"有些网络慢、有些正常"。curl 用 --http3 可显式验证端点是否真支持。
  3. 性能优化的元教训:Marx 展示的"两个正确的优化目标互相打架"(多路复用利于抗丢包 vs 顺序发送利于尽早执行)是好架构讨论的范本——先问"这个优化的收益在什么网络条件下兑现",再决定要不要做。
  4. 协议设计的下沉思想可迁移:QUIC 把 HTTP/2 的流概念下沉到传输层、把 TLS 揉进握手,本质是"当某层看不见上层结构时,把结构搬到能看见它的那层"。排查分层系统(数据库索引之于查询、缓存之于检索)时同样适用。
  5. 写作素材:Marx 用 11112222 vs 12121212 的字符画讲多路复用、用"单一收银台的超市"类比 HOL——把协议机制翻译成可画图的记号系统,是技术写作的高杠杆动作;我写 HTTP/3 介绍文时可直接借这个框架。
  6. 保持对"营销数字"的警惕:41.2% 是支持率不是流量;"QUIC 消除队头阻塞"为真但在多数网页场景收益有限——引用任何协议数据前先分清 measurement 口径。

附录 A:关键原文引述

  1. "When a single (slow) object prevents other/following objects from making progress" —— Marx,HOL blocking 定义
  2. "because the parallel nature of HTTP/2's multiplexing is not visible to TCP's loss recovery mechanisms, a lost or reordered packet causes all active transactions to experience a stall regardless of whether that transaction was directly impacted by the lost packet." —— RFC 9114 §1.1
  3. "Streams are independent of each other, so one stream that is blocked or suffers packet loss does not prevent progress on other streams." —— RFC 9114 §2
  4. "QUIC also incorporates TLS 1.3 … offering comparable confidentiality and integrity to running TLS over TCP, with the improved connection setup latency of TCP Fast Open." —— RFC 9114 §1.2
  5. "Because HPACK relies on in-order transmission of compressed field sections (a guarantee not provided by QUIC), HTTP/3 replaces HPACK with QPACK." —— RFC 9114 §2
  6. "Connectivity problems (e.g., blocking UDP) can result in a failure to establish a QUIC connection; clients SHOULD attempt to use TCP-based versions of HTTP in this case." —— RFC 9114 §3.1
  7. "HTTP/2 specifies priority assignments in PRIORITY frames and (optionally) in HEADERS frames. HTTP/3 does not provide a means of signaling priority." —— RFC 9114 附录 A.2.1
  8. "In QUIC the streams are provided by the transport itself, while in HTTP/2 the streams were done within the HTTP layer." —— Stenberg《HTTP/3 explained》
  9. "QUIC retains ordering within a single resource stream but no longer across individual streams." —— Marx
  10. "QUIC and HTTP/3's HOL blocking removal probably won't do all that much for Web performance in the majority of the cases." / "especially 0-RTT will provide the most Web performance benefits" —— Marx
  11. "pipelining solves HOL blocking for requests, but not for responses" —— Marx(引 HTTP/1.1 规范:"A server MUST send its responses to those [pipelined] requests in the same order that the requests were received.")
  12. "Officially standardized in May 2015, HTTP/2 use peaked in January 2022 at 46.9% of all websites" / "By October 2022, 26% of all websites were using HTTP/3." —— MDN
  13. "QUIC separates out the layer 4 transport connection from the layer 3 IP flow, allowing for migration between different networks without disruption." —— Cloudflare
  14. "Google started work on an early version of QUIC in 2012. In 2016 it was adopted by the Internet Engineering Task Force (IETF) … the now-standard version of QUIC published as RFC 9000." —— Cloudflare

附录 B:本次检索方式说明

← 资料库今日播报 →