關(guān)于我們
書單推薦
新書推薦
|
HTTP/2 in Action 中文版 讀者對象:本書適合網(wǎng)站開發(fā)及運(yùn)維人員,以及正考慮要實(shí)現(xiàn)HTTP/2或者希望了解HTTP/2如何工作的讀者。
本書以易于理解、方便上手的方式,使用貼近用戶的實(shí)例來解釋 HTTP/2 協(xié)議。本書首先介紹為什么要升級到 HTTP/2 以及升級的方法 ;然后逐步深入,詳細(xì)解釋了 HTTP/2 協(xié)議本身及其對Web 開發(fā)的影響 ;之后介紹了部分高級內(nèi)容,如流狀態(tài)、HPACK 等 ;最后探討了 HTTP 的未來。本書對于 Web 開發(fā)者和運(yùn)維工程師來說是一本很有價(jià)值的參考書。
Barry Pollard 是一位專業(yè)軟件開發(fā)者,在開發(fā)、支持軟件和基礎(chǔ)架構(gòu)方向擁有近20年的行業(yè)經(jīng)驗(yàn)。他對Web技術(shù),性能調(diào)優(yōu),安全以及技術(shù)實(shí)踐非常感興趣。他的博客是https://www.tunetheweb.com,您也可以在Twitter上找到他@tunetheweb。
鄭維智,Akamai公司高級企業(yè)架構(gòu)師,專注于公司的主要客戶及戰(zhàn)略合作伙伴。他也是Web性能優(yōu)化和HTTP/2的布道者,為Akamai的產(chǎn)品開發(fā)團(tuán)隊(duì)提供技術(shù)建議和客戶反饋。
第1部分 向HTTP/2靠攏
第1章 萬維網(wǎng)與HTTP....................................................................................................3 1.1 萬維網(wǎng)的原理 .......................................................................................................3 1.1.1 因特網(wǎng)與萬維網(wǎng) .......................................................................................4 1.1.2 打開網(wǎng)頁時(shí)會(huì)發(fā)生什么 ...........................................................................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 查看、發(fā)送和接收HTTP消息的工具 ...............................................................32 1.5.1 瀏覽器開發(fā)者工具 .................................................................................32 1.5.2 發(fā)送 HTTP 請求 .....................................................................................34 1.5.3 其他工具 .................................................................................................35 總結(jié) ..............................................................................................................................36 第2章 通向HTTP/2之路...............................................................................................37 2.1 HTTP/1.1和當(dāng)前的萬維網(wǎng) .................................................................................38 2.1.1 HTTP/1.1 根本的性能問題 ....................................................................40 2.1.2 HTTP/1.1 管道化 ....................................................................................42 2.1.3 網(wǎng)絡(luò)性能瀑布流圖 .................................................................................43 2.2 解決HTTP/1.1性能問題的方案 .........................................................................45 2.2.1 使用多個(gè) HTTP 連接 .............................................................................46 2.2.2 發(fā)送更少的請求 .....................................................................................49 2.2.3 HTTP/1 性能優(yōu)化總結(jié) ...........................................................................50 2.3 HTTP/1.1的其他問題 .........................................................................................50 2.4 實(shí)際案例 .............................................................................................................51 2.4.1 示例網(wǎng)站 1: amazon.com .......................................................................52 2.4.2 示例網(wǎng)站 2 : imgur.com .........................................................................56 2.4.3 這個(gè)問題究竟有多嚴(yán)重 .........................................................................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 總結(jié) ..............................................................................................................................70 第3章 升級到HTTP/2. ..................................................................................................72 3.1 HTTP/2的支持 ....................................................................................................72 3.1.1 瀏覽器對 HTTP/2 的支持 ......................................................................73 3.1.2 服務(wù)器對 HTTP/2 的支持 ......................................................................78 3.1.3 兼容不支持 HTTP/2 的情況 ..................................................................80 3.2 網(wǎng)站開啟HTTP/2的方法 ....................................................................................81 3.2.1 在 Web 服務(wù)器上開啟 HTTP/2..............................................................81 3.2.2 反向代理實(shí)現(xiàn) HTTP/2 ...........................................................................84 3.2.3 通過 CDN 實(shí)現(xiàn) HTTP/2 ........................................................................87 3.2.4 小結(jié) .........................................................................................................89 3.3 常見問題 .............................................................................................................89 總結(jié) ..............................................................................................................................93 第2部分 使用HTTP/2 第4章 HTTP/2協(xié)議基礎(chǔ)...............................................................................................97 4.1 為什么是HTTP/2而不是HTTP/1.2 ....................................................................97 4.1.1 使用二進(jìn)制格式替換文本格式 .............................................................99 4.1.2 多路復(fù)用代替同步請求 .......................................................................100 4.1.3 流的優(yōu)先級和流量控制 .......................................................................103 4.1.4 首部壓縮 ...............................................................................................104 4.1.5 服務(wù)端推送 ...........................................................................................105 4.2 如何創(chuàng)建一個(gè)HTTP/2連接 ..............................................................................105 4.2.1 使用 HTTPS 協(xié)商 .................................................................................106 4.2.2 使用 HTTP upgrade 首部 .....................................................................113 4.2.3 使用先驗(yàn)知識(shí) .......................................................................................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 幀數(shù)據(jù)格式 .............................................................................126 4.3.3 HTTP/2 消息流示例 .............................................................................128 4.3.4 其他幀 ...................................................................................................143 總結(jié) ............................................................................................................................148 第5章 實(shí)現(xiàn)HTTP/2推送.............................................................................................149 5.1 什么是HTTP/2服務(wù)端推送 ..............................................................................149 5.2 如何推送 ...........................................................................................................153 5.2.1 使用 HTTP link 首部推送 ....................................................................153 5.2.2 查看 HTTP/2 推送 ................................................................................156 5.2.3 使用 link 首部從下游系統(tǒng)推送 ...........................................................159 5.2.4 更早推送 ...............................................................................................162 5.2.5 使用其他方式推送 ...............................................................................168 5.3 HTTP/2推送在瀏覽器中如何運(yùn)作 ..................................................................171 5.3.1 查看推送緩存如何工作 .......................................................................172 5.3.2 使用 RST_STREAM 拒絕推送 ...........................................................175 5.4 如何實(shí)現(xiàn)條件推送 ...........................................................................................176 5.4.1 在服務(wù)端跟蹤推送的資源 ...................................................................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 應(yīng)該推送什么 .......................................................................................180 5.5.3 自動(dòng)化推送 ...........................................................................................181 5.6 HTTP/2推送常見問題 ......................................................................................182 5.7 HTTP/2推送對性能的影響 ..............................................................................184 5.8 對比推送和預(yù)加載 ...........................................................................................185 5.9 HTTP/2推送的其他應(yīng)用場景 ..........................................................................188 總結(jié) ............................................................................................................................190 第6章 HTTP/2優(yōu)化....................................................................................................192 6.1 HTTP/2對Web開發(fā)者的影響 ...........................................................................192 6.2 一些HTTP/1.1優(yōu)化方法是否成了反模式 .......................................................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 內(nèi)聯(lián)資源 ...............................................................................................203 6.2.7 總結(jié) .......................................................................................................203 6.3 在HTTP/2下依然有效的性能優(yōu)化技術(shù) ..........................................................204 6.3.1 減少要傳輸?shù)臄?shù)據(jù)量 ...........................................................................204 6.3.2 使用緩存防止重復(fù)發(fā)送數(shù)據(jù) ...............................................................211 6.3.3 Service Worker 可以大幅減少網(wǎng)絡(luò)加載 .............................................215 6.3.4 不發(fā)送不需要的內(nèi)容 ...........................................................................216 6.3.5 HTTP 資源暗示 ....................................................................................217 6.3.6 減少最后 1 公里的延遲 .......................................................................219 6.3.7 優(yōu)化 HTTPS ..........................................................................................219 6.3.8 和 HTTP 無關(guān)的性能優(yōu)化技術(shù) ...........................................................222 6.4 同時(shí)對HTTP/1.1和HTTP/2做優(yōu)化 ..................................................................222 6.4.1 計(jì)算 HTTP/2 流量 ................................................................................223 6.4.2 在服務(wù)端檢測 HTTP/2 支持 ................................................................224 6.4.3 在客戶端檢測 HTTP/2 支持 ................................................................228 6.4.4 連接合并 ...............................................................................................228 6.4.5 還要為 HTTP/1.1 的用戶優(yōu)化多久 .....................................................230 總結(jié) ............................................................................................................................231 第3部分 HTTP/2進(jìn)階 第7章 高級HTTP/2概念.............................................................................................235 7.1 流狀態(tài) ...............................................................................................................236 7.2 流量控制 ...........................................................................................................239 7.2.1 流量控制示例 .......................................................................................240 7.2.2 在服務(wù)器上設(shè)置流量控制 ...................................................................244 7.3 流優(yōu)先級 ...........................................................................................................244 7.3.1 流依賴關(guān)系 ...........................................................................................245 7.3.2 流權(quán)重 ...................................................................................................248 7.3.3 為什么優(yōu)先級策略如此復(fù)雜 ...............................................................251 7.3.4 Web 服務(wù)器和瀏覽器中的優(yōu)先級策略 ...............................................252 7.4 HTTP/2一致性測試 ..........................................................................................255 7.4.1 服務(wù)端一致性測試 ...............................................................................255 7.4.2 客戶端一致性測試 ...............................................................................258 總結(jié) ............................................................................................................................258 第8章 HPACK首部壓縮.............................................................................................259 8.1 為什么需要首部壓縮 .......................................................................................259 8.2 壓縮的運(yùn)作方式 ...............................................................................................261 8.2.1 查表法 ...................................................................................................262 8.2.2 更高效的編碼技術(shù) ...............................................................................263 8.2.3 Lookback( 反查 ) 壓縮 .........................................................................264 8.3 HTTP正文壓縮 .................................................................................................265 8.4 HTTP/2的HPACK首部壓縮 .............................................................................267 8.4.1 HPACK 靜態(tài)表 .....................................................................................268 8.4.2 HPACK 動(dòng)態(tài)表 .....................................................................................269 8.4.3 HPACK 首部類型 .................................................................................269 8.4.4 Huffman 編碼表 ...................................................................................275 8.4.5 Huffman 編碼腳本 ...............................................................................276 8.4.6 為什么 Huffman 編碼不總是最佳的 ..................................................278 8.5 HPACK壓縮實(shí)例 ..............................................................................................279 8.6 客戶端和服務(wù)端對HPACK的實(shí)現(xiàn) ..................................................................285 8.7 HPACK的價(jià)值 ..................................................................................................287 總結(jié) ............................................................................................................................287 第4部分 HTTP的未來 第9章 TCP、QUIC和HTTP/3....................................................................................291 9.1 TCP的低效率因素,以及HTTP ......................................................................292 9.1.1 創(chuàng)建 HTTP 連接的延遲 .......................................................................293 9.1.2 TCP 擁塞控制對性能的影響...............................................................295 9.1.3 TCP 低效率因素對 HTTP/2 的影響 ...................................................303 9.1.4 優(yōu)化 TCP ...............................................................................................307 9.1.5 TCP 和 HTTP 的未來...........................................................................313 9.2 QUIC .................................................................................................................313 9.2.1 QUIC 的性能優(yōu)勢 ................................................................................315 9.2.2 QUIC 和網(wǎng)絡(luò)技術(shù)棧 ...........................................................................316 9.2.3 什么是 UDP,為什么 QUIC 基于它 ..................................................317 9.2.4 標(biāo)準(zhǔn)化 QUIC ........................................................................................320 9.2.5 HTTP/2 和 QUIC 的不同 .....................................................................322 9.2.6 QUIC 的工具 ........................................................................................325 9.2.7 QUIC 實(shí)現(xiàn) ............................................................................................327 9.2.8 你應(yīng)該使用 QUIC 嗎 ...........................................................................327 總結(jié) ............................................................................................................................328 第10章 HTTP將何去何從..........................................................................................329 10.1 關(guān)于HTTP/2的爭議,以及它沒有解決的問題 ............................................330 10.1.1 反對 SPDY 的觀點(diǎn) .............................................................................330 10.1.2 隱私問題和 HTTP 中的狀態(tài) .............................................................332 10.1.3 HTTP 和加密 ......................................................................................337 10.1.4 傳輸協(xié)議的問題 .................................................................................340 10.1.5 HTTP/2 太過于復(fù)雜 ...........................................................................344 10.1.6 HTTP/2 是一種權(quán)宜之計(jì) ...................................................................345 10.2 HTTP/2的實(shí)際應(yīng)用 ........................................................................................345 10.3 HTTP/2的未來版本,HTTP/3或者HTTP/4會(huì)帶來什么 ..............................347 10.3.1 QUIC 是 HTTP/3 嗎 ...........................................................................347 10.3.2 更進(jìn)一步改進(jìn) HTTP 二進(jìn)制協(xié)議 ....................................................348 10.3.3 在傳輸層之上進(jìn)一步優(yōu)化 HTTP ......................................................348 10.3.4 什么時(shí)候會(huì)需要新的 HTTP 版本 .....................................................351 10.3.5 如何引入未來版本的 HTTP ..............................................................352 10.4 將HTTP當(dāng)作一個(gè)更通用的傳輸協(xié)議 ...........................................................352 10.4.1 使用 HTTP 語義和消息來傳遞非 Web 流量 ....................................353 10.4.2 使用 HTTP/2 二進(jìn)制成幀層 ..............................................................354 10.4.3 使用 HTTP 啟動(dòng)另一個(gè)協(xié)議 .............................................................355 總結(jié) ............................................................................................................................359 附錄A 將常見Web服務(wù)器升級到HTTP/2...................................................................360
你還可能感興趣
我要評論
|