《HTTP/2 in Action 中文版》简介:
《HTTP/2 in Action 中文版》以易于理解、方便上手的方式,使用贴近用户的实例来解释 HTTP/2 协议。本书首先介绍为什么要升级到 HTTP/2 以及升级的方法 ;然后逐步深入,详细解释了 HTTP/2 协议本身及其对Web 开发的影响 ;之后介绍了部分高级内容,如流状态、HPACK 等 ;最后探讨了 HTTP 的未来。本书对于 Web 开发者和运维工程师来说是一本很有价值的参考书。
《HTTP/2 in Action 中文版》目录:
第1部分 向HTTP/2靠拢
第1章 万维网与HTTP....................................................................................................3
1.1 万维网的原理 .......................................................................................................3
1.1.1 因特网与万维网 .......................................................................................4
1.1.2 打开网页时会发生什么 ...........................................................................5
1.2 什么是HTTP .........................................................................................................9
1.3 HTTP的语法和历史 ...........................................................................................16
1.3.1 HTTP/0.9 .................................................................................................16
1.3.2 HTTP/1.0 .................................................................................................17
1.3.3 HTTP/1.1 .................................................................................................23
1.4 HTTPS简介 .........................................................................................................29
1.5 查看、发送和接收HTTP消息的工具 ...............................................................32
1.5.1 浏览器开发者工具 .................................................................................32
1.5.2 发送 HTTP 请求 .....................................................................................34
1.5.3 其他工具 .................................................................................................35
总结 ..............................................................................................................................36
第2章 通向HTTP/2之路...............................................................................................37
2.1 HTTP/1.1和当前的万维网 .................................................................................38
2.1.1 HTTP/1.1 根本的性能问题 ....................................................................40
2.1.2 HTTP/1.1 管道化 ....................................................................................42
2.1.3 网络性能瀑布流图 .................................................................................43
2.2 解决HTTP/1.1性能问题的方案 .........................................................................45
2.2.1 使用多个 HTTP 连接 .............................................................................46
2.2.2 发送更少的请求 .....................................................................................49
2.2.3 HTTP/1 性能优化总结 ...........................................................................50
2.3 HTTP/1.1的其他问题 .........................................................................................50
2.4 实际案例 .............................................................................................................51
2.4.1 示例网站 1: amazon.com .......................................................................52
2.4.2 示例网站 2 : imgur.com .........................................................................56
2.4.3 这个问题究竟有多严重 .........................................................................57
2.5 从HTTP/1.1到HTTP/2 ........................................................................................58
2.5.1 SPDY .......................................................................................................58
2.5.2 HTTP/2 ....................................................................................................61
2.6 HTTP/2对Web性能的影响 .................................................................................62
2.6.1 展示 HTTP/2 能力的绝佳示例 ..............................................................62
2.6.2 对 HTTP/2 提升性能的期望 ..................................................................65
2.6.3 HTTP/1.1 的一些性能变通方法可能是反模式 ....................................70
总结 ..............................................................................................................................70
第3章 升级到HTTP/2. ..................................................................................................72
3.1 HTTP/2的支持 ....................................................................................................72
3.1.1 浏览器对 HTTP/2 的支持 ......................................................................73
3.1.2 服务器对 HTTP/2 的支持 ......................................................................78
3.1.3 兼容不支持 HTTP/2 的情况 ..................................................................80
3.2 网站开启HTTP/2的方法 ....................................................................................81
3.2.1 在 Web 服务器上开启 HTTP/2..............................................................81
3.2.2 反向代理实现 HTTP/2 ...........................................................................84
3.2.3 通过 CDN 实现 HTTP/2 ........................................................................87
3.2.4 小结 .........................................................................................................89
3.3 常见问题 .............................................................................................................89
总结 ..............................................................................................................................93
第2部分 使用HTTP/2
第4章 HTTP/2协议基础...............................................................................................97
4.1 为什么是HTTP/2而不是HTTP/1.2 ....................................................................97
4.1.1 使用二进制格式替换文本格式 .............................................................99
4.1.2 多路复用代替同步请求 .......................................................................100
4.1.3 流的优先级和流量控制 .......................................................................103
4.1.4 首部压缩 ...............................................................................................104
4.1.5 服务端推送 ...........................................................................................105
4.2 如何创建一个HTTP/2连接 ..............................................................................105
4.2.1 使用 HTTPS 协商 .................................................................................106
4.2.2 使用 HTTP upgrade 首部 .....................................................................113
4.2.3 使用先验知识 .......................................................................................116
4.2.4 HTTP Alternative Services ....................................................................117
4.2.5 HTTP/2 前奏消息 .................................................................................117
4.3 HTTP/2帧 ..........................................................................................................119
4.3.1 查看 HTTP/2 帧 ....................................................................................119
4.3.2 HTTP/2 帧数据格式 .............................................................................126
4.3.3 HTTP/2 消息流示例 .............................................................................128
4.3.4 其他帧 ...................................................................................................143
总结 ............................................................................................................................148
第5章 实现HTTP/2推送.............................................................................................149
5.1 什么是HTTP/2服务端推送 ..............................................................................149
5.2 如何推送 ...........................................................................................................153
5.2.1 使用 HTTP link 首部推送 ....................................................................153
5.2.2 查看 HTTP/2 推送 ................................................................................156
5.2.3 使用 link 首部从下游系统推送 ...........................................................159
5.2.4 更早推送 ...............................................................................................162
5.2.5 使用其他方式推送 ...............................................................................168
5.3 HTTP/2推送在浏览器中如何运作 ..................................................................171
5.3.1 查看推送缓存如何工作 .......................................................................172
5.3.2 使用 RST_STREAM 拒绝推送 ...........................................................175
5.4 如何实现条件推送 ...........................................................................................176
5.4.1 在服务端跟踪推送的资源 ...................................................................176
5.4.2 使用 HTTP 条件请求 ...........................................................................176
5.4.3 使用基于 cookie 的推送 ......................................................................177
5.4.4 使用缓存摘要 .......................................................................................178
5.5 推送什么 ...........................................................................................................179
5.5.1 你能推送什么 .......................................................................................179
5.5.2 应该推送什么 .......................................................................................180
5.5.3 自动化推送 ...........................................................................................181
5.6 HTTP/2推送常见问题 ......................................................................................182
5.7 HTTP/2推送对性能的影响 ..............................................................................184
5.8 对比推送和预加载 ...........................................................................................185
5.9 HTTP/2推送的其他应用场景 ..........................................................................188
总结 ............................................................................................................................190
第6章 HTTP/2优化....................................................................................................192
6.1 HTTP/2对Web开发者的影响 ...........................................................................192
6.2 一些HTTP/1.1优化方法是否成了反模式 .......................................................194
6.2.1 HTTP/2 请求依然有开销 .....................................................................194
6.2.2 HTTP/2 不是没有限制 .........................................................................197
6.2.3 越大的资源压缩越有效 .......................................................................199
6.2.4 带宽限制和资源竞争 ...........................................................................201
6.2.5 域名分片 ...............................................................................................202
6.2.6 内联资源 ...............................................................................................203
6.2.7 总结 .......................................................................................................203
6.3 在HTTP/2下依然有效的性能优化技术 ..........................................................204
6.3.1 减少要传输的数据量 ...........................................................................204
6.3.2 使用缓存防止重复发送数据 ...............................................................211
6.3.3 Service Worker 可以大幅减少网络加载 .............................................215
6.3.4 不发送不需要的内容 ...........................................................................216
6.3.5 HTTP 资源暗示 ....................................................................................217
6.3.6 减少最后 1 公里的延迟 .......................................................................219
6.3.7 优化 HTTPS ..........................................................................................219
6.3.8 和 HTTP 无关的性能优化技术 ...........................................................222
6.4 同时对HTTP/1.1和HTTP/2做优化 ..................................................................222
6.4.1 计算 HTTP/2 流量 ................................................................................223
6.4.2 在服务端检测 HTTP/2 支持 ................................................................224
6.4.3 在客户端检测 HTTP/2 支持 ................................................................228
6.4.4 连接合并 ...............................................................................................228
6.4.5 还要为 HTTP/1.1 的用户优化多久 .....................................................230
总结 ............................................................................................................................231
第3部分 HTTP/2进阶
第7章 高级HTTP/2概念.............................................................................................235
7.1 流状态 ...............................................................................................................236
7.2 流量控制 ...........................................................................................................239
7.2.1 流量控制示例 .......................................................................................240
7.2.2 在服务器上设置流量控制 ...................................................................244
7.3 流优先级 ...........................................................................................................244
7.3.1 流依赖关系 ...........................................................................................245
7.3.2 流权重 ...................................................................................................248
7.3.3 为什么优先级策略如此复杂 ...............................................................251
7.3.4 Web 服务器和浏览器中的优先级策略 ...............................................252
7.4 HTTP/2一致性测试 ..........................................................................................255
7.4.1 服务端一致性测试 ...............................................................................255
7.4.2 客户端一致性测试 ...............................................................................258
总结 ............................................................................................................................258
第8章 HPACK首部压缩.............................................................................................259
8.1 为什么需要首部压缩 .......................................................................................259
8.2 压缩的运作方式 ...............................................................................................261
8.2.1 查表法 ...................................................................................................262
8.2.2 更高效的编码技术 ...............................................................................263
8.2.3 Lookback( 反查 ) 压缩 .........................................................................264
8.3 HTTP正文压缩 .................................................................................................265
8.4 HTTP/2的HPACK首部压缩 .............................................................................267
8.4.1 HPACK 静态表 .....................................................................................268
8.4.2 HPACK 动态表 .....................................................................................269
8.4.3 HPACK 首部类型 .................................................................................269
8.4.4 Huffman 编码表 ...................................................................................275
8.4.5 Huffman 编码脚本 ...............................................................................276
8.4.6 为什么 Huffman 编码不总是最佳的 ..................................................278
8.5 HPACK压缩实例 ..............................................................................................279
8.6 客户端和服务端对HPACK的实现 ..................................................................285
8.7 HPACK的价值 ..................................................................................................287
总结 ............................................................................................................................287
第4部分 HTTP的未来
第9章 TCP、QUIC和HTTP/3....................................................................................291
9.1 TCP的低效率因素,以及HTTP ......................................................................292
9.1.1 创建 HTTP 连接的延迟 .......................................................................293
9.1.2 TCP 拥塞控制对性能的影响...............................................................295
9.1.3 TCP 低效率因素对 HTTP/2 的影响 ...................................................303
9.1.4 优化 TCP ...............................................................................................307
9.1.5 TCP 和 HTTP 的未来...........................................................................313
9.2 QUIC .................................................................................................................313
9.2.1 QUIC 的性能优势 ................................................................................315
9.2.2 QUIC 和网络技术栈 ...........................................................................316
9.2.3 什么是 UDP,为什么 QUIC 基于它 ..................................................317
9.2.4 标准化 QUIC ........................................................................................320
9.2.5 HTTP/2 和 QUIC 的不同 .....................................................................322
9.2.6 QUIC 的工具 ........................................................................................325
9.2.7 QUIC 实现 ............................................................................................327
9.2.8 你应该使用 QUIC 吗 ...........................................................................327
总结 ............................................................................................................................328
第10章 HTTP将何去何从..........................................................................................329
10.1 关于HTTP/2的争议,以及它没有解决的问题 ............................................330
10.1.1 反对 SPDY 的观点 .............................................................................330
10.1.2 隐私问题和 HTTP 中的状态 .............................................................332
10.1.3 HTTP 和加密 ......................................................................................337
10.1.4 传输协议的问题 .................................................................................340
10.1.5 HTTP/2 太过于复杂 ...........................................................................344
10.1.6 HTTP/2 是一种权宜之计 ...................................................................345
10.2 HTTP/2的实际应用 ........................................................................................345
10.3 HTTP/2的未来版本,HTTP/3或者HTTP/4会带来什么 ..............................347
10.3.1 QUIC 是 HTTP/3 吗 ...........................................................................347
10.3.2 更进一步改进 HTTP 二进制协议 ....................................................348
10.3.3 在传输层之上进一步优化 HTTP ......................................................348
10.3.4 什么时候会需要新的 HTTP 版本 .....................................................351
10.3.5 如何引入未来版本的 HTTP ..............................................................352
10.4 将HTTP当作一个更通用的传输协议 ...........................................................352
10.4.1 使用 HTTP 语义和消息来传递非 Web 流量 ....................................353
10.4.2 使用 HTTP/2 二进制成帧层 ..............................................................354
10.4.3 使用 HTTP 启动另一个协议 .............................................................355
总结 ............................................................................................................................359
附录A 将常见Web服务器升级到HTTP/2...................................................................360
· · · · · ·