第一部分 HTTP:Web 的基礎
第1 章 HTTP 概述 ............................................................................................................................3
1.1 HTTP——因特網的多媒體信使 ...............................................................................................4
1.2 Web 客戶端和服務器 .................................................................................................................4
1.3 資源 ............................................................................................................................................5
1.3.1 媒體類型 ........................................................................................................................6
1.3.2 URI.................................................................................................................................7
1.3.3 URL ...............................................................................................................................7
1.3.4 URN ...............................................................................................................................8
1.4 事務 ............................................................................................................................................9
1.4.1 方法 ...............................................................................................................................9
1.4.2 狀態碼 ..........................................................................................................................10
1.4.3 Web 頁麵中可以包含多個對象 ..................................................................................10
1.5 報文 ..........................................................................................................................................11
1.6 連接 ..........................................................................................................................................13
1.6.1 TCP/IP ..........................................................................................................................13
1.6.2 連接、IP 地址及端口號 ..............................................................................................14
1.6.3 使用Telnet 實例 ..........................................................................................................16
1.7 協議版本 ..................................................................................................................................18
1.8 Web 的結構組件 .......................................................................................................................19
1.8.1 代理 ..............................................................................................................................19
1.8.2 緩存 ..............................................................................................................................20
1.8.3 網關 ..............................................................................................................................20
1.8.4 隧道 ..............................................................................................................................21
1.8.5 Agent 代理 ....................................................................................................................21
1.9 起始部分的結束語 ...................................................................................................................22
1.10 更多信息 ................................................................................................................................22
1.10.1 HTTP 協議信息 ........................................................................................................22
1.10.2 曆史透視 ...................................................................................................................23
1.10.3 其他萬維網信息 .......................................................................................................23
第2 章 URL 與資源 ........................................................................................................................25
2.1 瀏覽因特網資源 .......................................................................................................................26
2.2 URL 的語法 ..............................................................................................................................28
2.2.1 方案——使用什麼協議 ..............................................................................................29
2.2.2 主機與端口 ..................................................................................................................30
2.2.3 用戶名和密碼 ..............................................................................................................30
2.2.4 路徑 ..............................................................................................................................31
2.2.5 參數 ..............................................................................................................................31
2.2.6 查詢字符串 ..................................................................................................................32
2.2.7 片段 ..............................................................................................................................33
2.3 URL 快捷方式 ..........................................................................................................................34
2.3.1 相對URL .....................................................................................................................34
2.3.2 自動擴展URL .............................................................................................................37
2.4 各種令人頭疼的字符 ...............................................................................................................38
2.4.1 URL 字符集 .................................................................................................................38
2.4.2 編碼機製 ......................................................................................................................38
2.4.3 字符限製 ......................................................................................................................39
2.4.4 另外一點說明 ..............................................................................................................40
2.5 方案的世界 ...............................................................................................................................40
2.6 未來展望 ..................................................................................................................................42
2.7 更多信息 ..................................................................................................................................44
第3 章 HTTP 報文 ..........................................................................................................................45
3.1 報文流 ......................................................................................................................................46
3.1.1 報文流入源端服務器 ..................................................................................................46
3.1.2 報文嚮下遊流動 ..........................................................................................................47
3.2 報文的組成部分 .......................................................................................................................47
3.2.1 報文的語法 ..................................................................................................................48
3.2.2 起始行 ..........................................................................................................................50
3.2.3 首部 ..............................................................................................................................53
3.2.4 實體的主體部分 ..........................................................................................................55
3.2.5 版本0.9 的報文 ...........................................................................................................55
3.3 方法 ..........................................................................................................................................56
3.3.1 安全方法 ......................................................................................................................56
3.3.2 GET ...............................................................................................................................56
3.3.3 HEAD ...........................................................................................................................57
3.3.4 PUT ...............................................................................................................................57
3.3.5 POST .............................................................................................................................58
3.3.6 TRACE .........................................................................................................................58
3.3.7 OPTIONS......................................................................................................................60
3.3.8 DELETE .......................................................................................................................60
3.3.9 擴展方法 ......................................................................................................................61
3.4 狀態碼 ......................................................................................................................................62
3.4.1 100 ~ 199——信息性狀態碼 ....................................................................................62
3.4.2 200 ~ 299——成功狀態碼 ........................................................................................63
3.4.3 300 ~ 399——重定嚮狀態碼 ....................................................................................64
3.4.4 400 ~ 499——客戶端錯誤狀態碼 ............................................................................68
3.4.5 500 ~ 599——服務器錯誤狀態碼 ............................................................................69
3.5 首部 ..........................................................................................................................................70
3.5.1 通用首部 ......................................................................................................................71
3.5.2 請求首部 ......................................................................................................................72
3.5.3 響應首部 ......................................................................................................................74
3.5.4 實體首部 ......................................................................................................................75
3.6 更多信息 ..................................................................................................................................77
第4 章 連接管理 ..............................................................................................................................79
4.1 TCP 連接..................................................................................................................................80
4.1.1 TCP 的可靠數據管道 ..................................................................................................80
4.1.2 TCP 流是分段的、由IP 分組傳送.............................................................................81
4.1.3 保持TCP 連接的正確運行 .........................................................................................82
4.1.4 用TCP 套接字編程 .....................................................................................................84
4.2 對TCP 性能的考慮..................................................................................................................85
4.2.1 HTTP 事務的時延 .......................................................................................................86
4.2.2 性能聚焦區域 ..............................................................................................................87
4.2.3 TCP 連接的握手時延 ..................................................................................................87
4.2.4 延遲確認 ......................................................................................................................88
4.2.5 TCP 慢啓動 ..................................................................................................................89
4.2.6 Nagle 算法與TCP_NODELAY ...................................................................................89
4.2.7 TIME_WAIT 纍積與端口耗盡 ....................................................................................90
4.3 HTTP 連接的處理 ....................................................................................................................91
4.3.1 常被誤解的Connection 首部 .................................................................................91
4.3.2 串行事務處理時延 ......................................................................................................92
4.4 並行連接 ..................................................................................................................................94
4.4.1 並行連接可能會提高頁麵的加載速度 ......................................................................94
4.4.2 並行連接不一定更快 ..................................................................................................95
4.4.3 並行連接可能讓人“感覺”更快一些 ......................................................................95
4.5 持久連接 ..................................................................................................................................96
4.5.1 持久以及並行連接 ......................................................................................................96
4.5.2 HTTP/1.0+ Keep-Alive 連接 .......................................................................................97
4.5.3 keep-Alive 操作 ............................................................................................................98
4.5.4 keep-Alive 選項 ............................................................................................................98
4.5.5 keep-Alive 連接的限製和規則 ....................................................................................99
4.5.6 keep-Alive 和啞代理 ..................................................................................................100
4.5.7 插入Proxy-Connection ......................................................................................102
4.5.8 HTTP/1.1 持久連接 ...................................................................................................104
4.5.9 持久連接的限製和規則 ............................................................................................104
4.6 管道化連接 .............................................................................................................................105
4.7 關閉連接的奧秘 .....................................................................................................................106
4.7.1 “任意”解除連接 ......................................................................................................106
4.7.2 Content-Length 及截尾操作 ...............................................................................107
4.7.3 連接關閉容限、重試以及冪等性 ............................................................................107
4.7.4 正常關閉連接 ............................................................................................................108
4.8 更多信息 ................................................................................................................................110
4.8.1 HTTP 連接 .................................................................................................................110
4.8.2 HTTP 性能問題 .........................................................................................................110
4.8.3 TCP/IP ........................................................................................................................ 111
第二部分 HTTP 結構
第5 章 Web 服務器 ......................................................................................................................115
5.1 各種形狀和尺寸的Web 服務器 ............................................................................................116
5.1.1 Web 服務器的實現 ....................................................................................................116
5.1.2 通用軟件Web 服務器 ...............................................................................................117
5.1.3 Web 服務器設備 ........................................................................................................117
5.1.4 嵌入式Web 服務器 ...................................................................................................118
5.2 最小的Perl Web 服務器 ........................................................................................................118
5.3 實際的Web 服務器會做些什麼 ............................................................................................120
5.4 第一步——接受客戶端連接 .................................................................................................121
5.4.1 處理新連接 ................................................................................................................121
5.4.2 客戶端主機名識彆 ....................................................................................................122
5.4.3 通過ident 確定客戶端用戶 ......................................................................................122
5.5 第二步——接收請求報文 .....................................................................................................123
5.5.1 報文的內部錶示法 ....................................................................................................124
5.5.2 連接的輸入/ 輸齣處理結構 .....................................................................................125
5.6 第三步——處理請求 .............................................................................................................126
5.7 第四步——對資源的映射及訪問 .........................................................................................126
5.7.1 docroot ........................................................................................................................127
5.7.2 目錄列錶 ....................................................................................................................129
5.7.3 動態內容資源的映射 ................................................................................................130
5.7.4 服務器端包含項(SSI) .............................................................................................131
5.7.5 訪問控製 ....................................................................................................................131
5.8 第五步——構建響應 .............................................................................................................131
5.8.1 響應實體 ....................................................................................................................131
5.8.2 MIME 類型.................................................................................................................132
5.8.3 重定嚮 ........................................................................................................................133
5.9 第六步——發送響應 .............................................................................................................134
5.10 第七步——記錄日誌 ...........................................................................................................134
5.11 更多信息 ...............................................................................................................................134
第6 章 代理 ....................................................................................................................................135
6.1 Web 的中間實體 .....................................................................................................................136
6.1.1 私有和共享代理 ........................................................................................................136
6.1.2 代理與網關的對比 ....................................................................................................137
6.2 為什麼使用代理 .....................................................................................................................138
6.3 代理會去往何處 .....................................................................................................................143
6.3.1 代理服務器的部署 ....................................................................................................144
6.3.2 代理的層次結構 ........................................................................................................144
6.3.3 代理是如何獲取流量的 ............................................................................................147
6.4 客戶端的代理設置 .................................................................................................................148
6.4.1 客戶端的代理配置:手工 ........................................................................................149
6.4.2 客戶端代理配置:PAC 文件 ....................................................................................149
6.4.3 客戶端代理配置:WPAD .........................................................................................150
6.5 與代理請求有關的棘手問題 .................................................................................................151
6.5.1 代理URI 與服務器URI 的不同 ...............................................................................151
6.5.2 與虛擬主機一樣的問題 ............................................................................................152
6.5.3 攔截代理會收到部分URI.........................................................................................153
6.5.4 代理既可以處理代理請求,也可以處理服務器請求 ............................................154
6.5.5 轉發過程中對URI 的修改........................................................................................154
6.5.6 URI 的客戶端自動擴展和主機名解析.....................................................................155
6.5.7 沒有代理時URI 的解析............................................................................................155
6.5.8 有顯式代理時URI 的解析........................................................................................156
6.5.9 有攔截代理時解析URI.............................................................................................156
6.6 追蹤報文 ................................................................................................................................157
6.6.1 Via 首部.....................................................................................................................158
6.6.2 TRACE 方法 ..............................................................................................................162
6.7 代理認證 ................................................................................................................................164
6.8 代理的互操作性 .....................................................................................................................165
6.8.1 處理代理不支持的首部和方法 ................................................................................165
6.8.2 OPTIONS:發現可選特性的支持............................................................................166
6.8.3 Allow 首部 ................................................................................................................167
6.9 更多信息 ................................................................................................................................167
第7 章 緩存 ....................................................................................................................................169
7.1 冗餘的數據傳輸 .....................................................................................................................170
7.2 帶寬瓶頸 ................................................................................................................................170
7.3 瞬間擁塞 ................................................................................................................................171
7.4 距離時延 ................................................................................................................................172
7.5 命中和未命中的 .....................................................................................................................173
7.5.1 再驗證 ........................................................................................................................173
7.5.2 命中率 ........................................................................................................................175
7.5.3 字節命中率 ................................................................................................................176
7.5.4 區分命中和未命中的情況 ........................................................................................176
7.6 緩存的拓撲結構 .....................................................................................................................177
7.6.1 私有緩存 ....................................................................................................................177
7.6.2 公有代理緩存 ............................................................................................................177
7.6.3 代理緩存的層次結構 ................................................................................................179
7.6.4 網狀緩存、內容路由以及對等緩存 ........................................................................180
7.7 緩存的處理步驟 .....................................................................................................................181
7.7.1 第一步——接收 ........................................................................................................181
7.7.2 第二步——解析 ........................................................................................................182
7.7.3 第三步——查找 ........................................................................................................182
7.7.4 第四步——新鮮度檢測 ............................................................................................182
7.7.5 第五步——創建響應 ................................................................................................182
7.7.6 第六步——發送 ........................................................................................................183
7.7.7 第七步——日誌 ........................................................................................................183
7.7.8 緩存處理流程圖 ........................................................................................................183
7.8 保持副本的新鮮 .....................................................................................................................183
7.8.1 文檔過期 ....................................................................................................................184
7.8.2 過期日期和年齡 ........................................................................................................185
7.8.3 服務器再驗證 ............................................................................................................185
7.8.4 用條件方法進行再驗證 ............................................................................................186
7.8.5 If-Modified-Since:Date 再驗證 .......................................................................187
7.8.6 If-None-Match????實體標簽再驗證 .......................................................................189
7.8.7 強弱驗證器 ................................................................................................................190
7.8.8 什麼時候應該使用實體標簽和最近修改日期 ........................................................190
7.9 對緩存能力的控製 .................................................................................................................191
7.9.1 no-Store 與no-Cache 響應首部 .........................................................................191
7.9.2 Max-Age 響應首部 ...................................................................................................192
7.9.3 Expires 響應首部 ...................................................................................................192
7.9.4 Must-Revalidate 響應首部 .................................................................................192
7.9.5 試探性過期 ................................................................................................................193
7.9.6 客戶端的新鮮度限製 ................................................................................................194
7.9.7 注意事項 ....................................................................................................................194
7.10 設置緩存控製 .......................................................................................................................195
7.10.1 控製Apache 的HTTP 首部 ....................................................................................195
7.10.2 通過HTTP-EQUIV 控製HTML 緩存 ...................................................................196
7.11 詳細算法 ...............................................................................................................................197
7.11.1 年齡和新鮮生存期 ...................................................................................................198
7.11.2 使用期的計算 ...........................................................................................................198
7.11.3 完整的使用期計算算法 ...........................................................................................201
7.11.4 新鮮生存期計算 .......................................................................................................202
7.11.5 完整的服務器—新鮮度算法 ...................................................................................202
7.12 緩存和廣告 ...........................................................................................................................204
7.12.1 發布廣告者的兩難處境 ..........................................................................................204
7.12.2 發布者的響應 ..........................................................................................................204
7.12.3 日誌遷移 ..................................................................................................................205
7.12.4 命中計數和使用限製 ..............................................................................................205
7.13 更多信息 ...............................................................................................................................205
第8 章 集成點:網關隧道及中繼 .............................................................................................207
8.1 網關 ........................................................................................................................................208
8.2 協議網關 ................................................................................................................................210
8.2.1 HTTP/*:服務器端Web 網關 ..................................................................................211
8.2.2 HTTP/HTTPS:服務器端安全網關 .........................................................................212
8.2.3 HTTPS/HTTP 客戶端安全加速器網關 ....................................................................212
8.3 資源網關 ................................................................................................................................213
8.3.1 通用網關接口(CGI) ................................................................................................215
8.3.2 服務器擴展API .........................................................................................................215
8.4 應用程序接口和Web 服務 ....................................................................................................216
8.5 隧道 ........................................................................................................................................217
8.5.1 用CONNECT 建立HTTP 隧道................................................................................217
8.5.2 數據隧道、定時及連接管理 ....................................................................................219
8.5.3 SSL 隧道.....................................................................................................................219
8.5.4 SSL 隧道與HTTP/HTTPS 網關的對比 ...................................................................220
8.5.5 隧道認證 ....................................................................................................................221
8.5.6 隧道的安全性考慮 ....................................................................................................221
8.6 中繼 ........................................................................................................................................222
8.7 更多信息 ................................................................................................................................224
第9 章 Web 機器人 ......................................................................................................................225
9.1 爬蟲及爬行方式 .....................................................................................................................226
9.1.1 從哪兒開始:根集 ....................................................................................................226
9.1.2 鏈接的提取以及相對鏈接的標準化 ........................................................................227
9.1.3 避免環路的齣現 ........................................................................................................228
9.1.4 循環與復製 ................................................................................................................228
9.1.5 麵包屑留下的痕跡 ....................................................................................................229
9.1.6 彆名與機器人環路 ....................................................................................................230
9.1.7 規範化URL ...............................................................................................................230
9.1.8 文件係統連接環路 ....................................................................................................231
9.1.9 動態虛擬Web 空間 ...................................................................................................232
9.1.10 避免循環和重復 ......................................................................................................233
9.2 機器人的HTTP ......................................................................................................................236
9.2.1 識彆請求首部 ............................................................................................................236
9.2.2 虛擬主機 ....................................................................................................................236
9.2.3 條件請求 ....................................................................................................................237
9.2.4 對響應的處理 ............................................................................................................238
9.2.5 User-Agent 目標 ....................................................................................................239
9.3 行為不當的機器人 .................................................................................................................239
9.4 拒絕機器人訪問 .....................................................................................................................240
9.4.1 拒絕機器人訪問標準 ................................................................................................241
9.4.2 Web 站點和robots.txt 文件 .......................................................................................242
9.4.3 robots.txt 文件的格式 ................................................................................................243
9.4.4 其他有關robots.txt 的知識 .......................................................................................246
9.4.5 緩存和robots.txt 的過期 ...........................................................................................246
9.4.6 拒絕機器人訪問的Perl 代碼 ....................................................................................247
9.4.7 HTML 的robot-control 元標簽 ........................................................................249
9.5 機器人的規範 .........................................................................................................................251
9.6 搜索引擎 ................................................................................................................................254
9.6.1 大格局 ........................................................................................................................255
9.6.2 現代搜索引擎結構 ....................................................................................................255
9.6.3 全文索引 ....................................................................................................................255
9.6.4 發布查詢請求 ............................................................................................................257
9.6.5 對結果進行排序,並提供查詢結果 ........................................................................258
9.6.6 欺詐 ............................................................................................................................258
9.7 更多信息 ................................................................................................................................258
第10 章 HTTP-NG .......................................................................................................................261
10.1 HTTP 發展中存在的問題 ....................................................................................................262
10.2 HTTP-NG 的活動 .................................................................................................................263
10.3 模塊化及功能增強 ...............................................................................................................263
10.4 分布式對象 ...........................................................................................................................264
10.5 第一層——報文傳輸 ...........................................................................................................264
10.6 第二層——遠程調用 ...........................................................................................................265
10.7 第三層——Web 應用 ...........................................................................................................265
10.8 WebMUX ..............................................................................................................................265
10.9 二進製連接協議 ...................................................................................................................266
10.10 當前的狀態 .........................................................................................................................267
10.11 更多信息 .............................................................................................................................267
第三部分 識彆、認證與安全
第11 章 客戶端識彆與cookie 機製 ........................................................................................271
11.1 個性化接觸 ...........................................................................................................................272
11.2 HTTP 首部 ............................................................................................................................273
11.3 客戶端IP 地址 .....................................................................................................................274
11.4 用戶登錄 ...............................................................................................................................275
11.5 胖URL .................................................................................................................................277
11.6 cookie ...................................................................................................................................278
11.6.1 cookie 的類型 .........................................................................................................278
11.6.2 cookie 是如何工作的 .............................................................................................279
11.6.3 cookie 罐:客戶端的狀態 .....................................................................................280
11.6.4 不同站點使用不同的cookie .................................................................................282
11.6.5 cookie 成分 .............................................................................................................283
11.6.6 cookies 版本0(Netscape) ....................................................................................284
11.6.7 cookies 版本1(RFC 2965) ..................................................................................285
11.6.8 cookie 與會話跟蹤 .................................................................................................288
11.6.9 cookie 與緩存 .........................................................................................................290
11.6.10 cookie、安全性和隱私 ........................................................................................291
11.7 更多信息 ...............................................................................................................................292
第12 章 基本認證機製 ................................................................................................................293
12.1 認證 ......................................................................................................................................294
12.1.1 HTTP 的質詢/ 響應認證框架 ...............................................................................294
12.1.2 認證協議與首部 .....................................................................................................295
12.1.3 安全域 .....................................................................................................................296
12.2 基本認證 ...............................................................................................................................297
12.2.1 基本認證實例 .........................................................................................................298
12.2.2 Base-64 用戶名/ 密碼編碼 ....................................................................................298
12.2.3 代理認證 .................................................................................................................299
12.3 基本認證的安全缺陷 ...........................................................................................................300
12.4 更多信息 ...............................................................................................................................301
第13 章 摘要認證 .........................................................................................................................303
13.1 摘要認證的改進 ...................................................................................................................304
13.1.1 用摘要保護密碼的 .................................................................................................304
13.1.2 單嚮摘要 .................................................................................................................306
13.1.3 用隨機數防止重放攻擊 .........................................................................................307
13.1.4 摘要認證的握手機製 .............................................................................................307
13.2 摘要的計算 ...........................................................................................................................308
13.2.1 摘要算法的輸入數據 .............................................................................................308
13.2.2 算法H(d) 和KD(s,d) .............................................................................................310
13.2.3 與安全性相關的數據(A1) ..................................................................................310
13.2.4 與報文有關的數據(A2) ......................................................................................310
13.2.5 摘要算法總述 ....................................................................................................................311
13.2.6 摘要認證會話 .........................................................................................................312
13.2.7 預授權 .....................................................................................................................312
13.2.8 隨機數的選擇 .........................................................................................................315
13.2.9 對稱認證 .................................................................................................................315
13.3 增強保護質量 .......................................................................................................................316
13.3.1 報文完整性保護 .....................................................................................................316
13.3.2 摘要認證首部 .........................................................................................................317
13.4 應該考慮的實際問題 ...........................................................................................................317
13.4.1 多重質詢 .................................................................................................................318
13.4.2 差錯處理 .................................................................................................................318
13.4.3 保護空間 .................................................................................................................318
13.4.4 重寫URI .................................................................................................................319
13.4.5 緩存 .........................................................................................................................319
13.5 安全性考慮 ...........................................................................................................................320
13.5.1 首部篡改 .................................................................................................................320
13.5.2 重放攻擊 .................................................................................................................320
13.5.3 多重認證機製 .........................................................................................................320
13.5.4 詞典攻擊 .................................................................................................................321
13.5.5 惡意代理攻擊和中間人攻擊 .................................................................................321
13.5.6 選擇明文攻擊 .........................................................................................................321
13.5.7 存儲密碼 .................................................................................................................322
13.6 更多信息 ...............................................................................................................................322
第14 章 安全HTTP .....................................................................................................................323
14.1 保護HTTP 的安全 ...............................................................................................................324
14.2 數字加密 ...............................................................................................................................326
14.2.1 密碼編製的機製與技巧 .........................................................................................326
14.2.2 密碼 .........................................................................................................................327
14.2.3 密碼機 .....................................................................................................................328
14.2.4 使用瞭密鑰的密碼 .................................................................................................328
14.2.5 數字密碼 .................................................................................................................328
14.3 對稱密鑰加密技術 ...............................................................................................................330
14.3.1 密鑰長度與枚舉攻擊 .............................................................................................330
14.3.2 建立共享密鑰 .........................................................................................................332
14.4 公開密鑰加密技術 ...............................................................................................................332
14.4.1 RSA .........................................................................................................................333
14.4.2 混閤加密係統和會話密鑰 .....................................................................................334
14.5 數字簽名 ...............................................................................................................................334
14.6 數字證書 ...............................................................................................................................336
14.6.1 證書的主要內容 .....................................................................................................336
14.6.2 X.509 v3 證書 .........................................................................................................337
14.6.3 用證書對服務器進行認證 .....................................................................................338
14.7 HTTPS——細節介紹 ...........................................................................................................339
14.7.1 HTTPS 概述 ............................................................................................................339
14.7.2 HTTPS 方案 ............................................................................................................340
14.7.3 建立安全傳輸 .........................................................................................................341
14.7.4 SSL 握手 .................................................................................................................341
14.7.5 服務器證書 .............................................................................................................343
14.7.6 站點證書的有效性 .................................................................................................344
14.7.7 虛擬主機與證書 .....................................................................................................345
14.8 HTTPS 客戶端實例 ..............................................................................................................345
14.8.1 OpenSSL .................................................................................................................346
14.8.2 簡單的HTTPS 客戶端 ...........................................................................................347
14.8.3 執行OpenSSL 客戶端 ...........................................................................................350
14.9 通過代理以隧道形式傳輸安全流量 ...................................................................................351
14.10 更多信息 .............................................................................................................................353
14.10.1 HTTP 安全性 ........................................................................................................353
14.10.2 SSL 與TLS ...........................................................................................................353
14.10.3 公開密鑰基礎設施 ...............................................................................................354
14.10.4 數字密碼 ...............................................................................................................354
第四部分 實體、編碼和國際化
第15 章 實體和編碼 .....................................................................................................................357
15.1 報文是箱子,實體是貨物 ...................................................................................................359
15.1.1 實體主體 .................................................................................................................360
15.2 Content-Length: 實體的大小 ......................................................................................361
15.2.1 檢測截尾 .................................................................................................................361
15.2.2 錯誤的Content-Length ....................................................................................362
15.2.3 Content-Length 與持久連接 ............................................................................362
15.2.4 內容編碼 .................................................................................................................362
15.2.5 確定實體主體長度的規則 .....................................................................................362
15.3 實體摘要 ...............................................................................................................................364
15.4 媒體類型和字符集 ...............................................................................................................364
15.4.1 文本的字符編碼 .....................................................................................................365
15.4.2 多部分媒體類型 .....................................................................................................365
15.4.3 多部分錶格提交 .....................................................................................................366
15.4.4 多部分範圍響應 .....................................................................................................367
15.5 內容編碼 ...............................................................................................................................368
15.5.1 內容編碼過程 .........................................................................................................368
15.5.2 內容編碼類型 .........................................................................................................369
15.5.3 Accept-Encoding 首部 .....................................................................................369
15.6 傳輸編碼和分塊編碼 ...........................................................................................................371
15.6.1 可靠傳輸 .................................................................................................................371
15.6.2 Transfer-Encoding 首部 .................................................................................372
15.6.3 分塊編碼 .................................................................................................................373
15.6.4 內容編碼與傳輸編碼的結閤 .................................................................................375
15.6.5 傳輸編碼的規則 .....................................................................................................375
15.7 隨時間變化的實例 ...............................................................................................................375
15.8 驗證碼和新鮮度 ...................................................................................................................376
15.8.1 新鮮度 .....................................................................................................................377
15.8.2 有條件的請求與驗證碼 .........................................................................................378
15.9 範圍請求 ...............................................................................................................................380
15.10 差異編碼 .............................................................................................................................382
15.11 更多信息 .............................................................................................................................385
第16 章 國際化 ..............................................................................................................................387
16.1 HTTP 對國際性內容的支持 ................................................................................................388
16.2 字符集與HTTP ....................................................................................................................389
16.2.1 字符集是把字符轉換為二進製碼的編碼 .............................................................389
16.2.2 字符集和編碼如何工作 .........................................................................................390
16.2.3 字符集不對,字符就不對 .....................................................................................391
16.2.4 標準化的MIME charset 值 ....................................................................................391
16.2.5 Content-Type 首部和Charset 首部以及META 標誌 .................................393
16.2.6 Accept-Charset 首部 ........................................................................................393
16.3 多語言字符編碼入門 ...........................................................................................................394
16.3.1 字符集術語 .............................................................................................................394
16.3.2 字符集的命名很糟糕 .............................................................................................395
16.3.3 字符 .........................................................................................................................396
16.3.4 字形、連筆以及錶示形式 .....................................................................................396
16.3.5 編碼後的字符集 .....................................................................................................397
16.3.6 字符編碼方案 .........................................................................................................399
16.4 語言標記與HTTP ................................................................................................................402
16.4.1 Content-Language 首部 ...................................................................................402
16.4.2 Accept-Language 首部 .....................................................................................403
16.4.3 語言標記的類型 .....................................................................................................404
16.4.4 子標記 .....................................................................................................................404
16.4.5 大小寫 .....................................................................................................................405
16.4.6 IANA 語言標記注冊 ..............................................................................................405
16.4.7 第一個子標記——名字空間 .................................................................................405
16.4.8 第二個子標記——名字空間 .................................................................................406
16.4.9 其餘子標記——名字空間 .....................................................................................407
16.4.10 配置和語言有關的首選項 ...................................................................................407
16.4.11 語言標記參考錶 ...................................................................................................407
16.5 國際化的URI .......................................................................................................................408
16.5.1 全球性的可轉抄能力與有意義的字符的較量 .....................................................408
16.5.2 URI 字符集閤 .........................................................................................................408
16.5.3 轉義和反轉義 .........................................................................................................409
16.5.4 轉義國際化字符 .....................................................................................................409
16.5.5 URI 中的模態切換 .................................................................................................410
16.6 其他需要考慮的地方 ...........................................................................................................410
16.6.1 首部和不閤規範的數據 .........................................................................................410
16.6.2 日期 .........................................................................................................................411
16.6.3 域名 .........................................................................................................................411
16.7 更多信息 ...............................................................................................................................411
16.7.1 附錄 .........................................................................................................................411
16.7.2 互聯網的國際化 .....................................................................................................411
16.7.3 國際標準 .................................................................................................................412
第17 章 內容協商與轉碼 ............................................................................................................413
17.1 內容協商技術 .......................................................................................................................414
17.2 客戶端驅動的協商 ...............................................................................................................415
17.3 服務器驅動的協商 ...............................................................................................................415
17.3.1 內容協商首部集 .....................................................................................................416
17.3.2 內容協商首部中的質量值 .....................................................................................417
17.3.3 隨其他首部集而變化 .............................................................................................417
17.3.4 Apache 中的內容協商 ............................................................................................417
17.3.5 服務器端擴展 .........................................................................................................418
17.4 透明協商 ...............................................................................................................................419
17.4.1 進行緩存與備用候選 .............................................................................................419
17.4.2 Vary 首部 ...............................................................................................................420
17.5 轉碼 ......................................................................................................................................422
17.5.1 格式轉換 .................................................................................................................422
17.5.2 信息綜閤 .................................................................................................................423
17.5.3 內容注入 .................................................................................................................423
17.5.4 對比轉碼與靜態預生成 .........................................................................................423
17.6 下一步計劃 ...........................................................................................................................424
17.7 更多信息 ...............................................................................................................................424
第五部分 內容發布與分發
第18 章 Web 主機托管 ...............................................................................................................429
18.1 主機托管服務 .......................................................................................................................430
18.2 虛擬主機托管 .......................................................................................................................431
18.2.1 虛擬服務器請求缺乏主機信息 .............................................................................432
18.2.2 設法讓虛擬主機托管正常工作 .............................................................................433
18.2.3 HTTP/1.1 的Host 首部 ..........................................................................................437
18.3 使網站更可靠 .......................................................................................................................438
18.3.1 鏡像的服務器集群 .................................................................................................438
18.3.2 內容分發網絡 .........................................................................................................440
18.3.3 CDN 中的反嚮代理緩存 .......................................................................................440
18.3.4 CDN 中的代理緩存 ...............................................................................................440
18.4 讓網站更快 ...........................................................................................................................441
18.5 更多信息 ...............................................................................................................................441
第19 章 發布係統 .........................................................................................................................443
19.1 FrontPage 為支持發布而做的服務器擴展 .........................................................................444
19.1.1 FrontPage 服務器擴展 ...........................................................................................444
19.1.2 FrontPage 術語錶 ...................................................................................................445
19.1.3 FrontPage 的RPC 協議 ..........................................................................................445
19.1.4 FrontPage 的安全模型 ...........................................................................................448
19.2 WebDAV 與協作寫作 ..........................................................................................................449
19.2.1 WebDAV 的方法.....................................................................................................449
19.2.2 WebDAV 與XML ...................................................................................................450
19.2.3 WebDAV 首部集.....................................................................................................451
19.2.4 WebDAV 的鎖定與防止覆寫.................................................................................452
19.2.5 LOCK 方法 ...............................................................................................................453
19.2.6 UNLOCK 方法 ..........................................................................................................456
19.2.7 屬性和元數據 .........................................................................................................456
19.2.8 PROPFIND 方法 .....................................................................................................457
19.2.9 PROPPATCH 方法 ...................................................................................................459
19.2.10 集閤與名字空間管理 ...........................................................................................460
19.2.11 MKCOL 方法...........................................................................................................460
19.2.12 DELETE 方法 ........................................................................................................461
19.2.13 COPY 與MOVE 方法 .............................................................................................462
19.2.14 增強的HTTP/1.1 方法 .........................................................................................465
19.2.15 WebDAV 中的版本管理.......................................................................................466
19.2.16 WebDAV 的未來發展...........................................................................................466
19.3 更多信息 ...............................................................................................................................467
第20 章 重定嚮與負載均衡 .......................................................................................................469
20.1 為什麼要重定嚮 ...................................................................................................................470
20.2 重定嚮到何地 .......................................................................................................................471
20.3 重定嚮協議概覽 ...................................................................................................................471
20.4 通用的重定嚮方法 ...............................................................................................................474
20.4.1 HTTP 重定嚮 ..........................................................................................................474
20.4.2 DNS 重定嚮 ............................................................................................................475
20.4.3 任播尋址 .................................................................................................................480
20.4.4 IP MAC 轉發 ..........................................................................................................481
20.4.5 IP 地址轉發 ............................................................................................................482
20.4.6 網元控製協議 .........................................................................................................484
20.5 代理的重定嚮方法 ...............................................................................................................485
20.5.1 顯式瀏覽器配置 .....................................................................................................485
20.5.2 代理自動配置 .........................................................................................................485
20.5.3 Web 代理自動發現協議 .........................................................................................487
20.6 緩存重定嚮方法 ...................................................................................................................492
20.7 因特網緩存協議 ...................................................................................................................496
20.8 緩存陣列路由協議 ...............................................................................................................497
20.9 超文本緩存協議 ...................................................................................................................500
20.9.1 HTCP 認證 ..............................................................................................................502
20.9.2 設置緩存策略 .........................................................................................................503
20.10 更多信息 .............................................................................................................................504
第21 章 日誌記錄與使用情況跟蹤 ..........................................................................................505
21.1 記錄的內容 ...........................................................................................................................506
21.2 日誌格式 ...............................................................................................................................507
21.2.1 常見日誌格式 .........................................................................................................507
21.2.2 組閤日誌格式 .........................................................................................................508
21.2.3 Netscape 的擴展日誌格式 .....................................................................................509
21.2.4 Netscape 擴展2 日誌格式 .....................................................................................510
21.2.5 Squid 代理日誌格式 ...............................................................................................512
21.3 命中率測量 ...........................................................................................................................515
21.3.1 概述 .........................................................................................................................515
21.3.2 Meter 首部 ..............................................................................................................516
21.4 關於隱私的考慮 ...................................................................................................................517
21.5 更多信息 ...............................................................................................................................518
第六部分 附 錄
附錄A URI 方案 ............................................................................................................................521
附錄B HTTP 狀態碼 ....................................................................................................................529
附錄C HTTP 首部參考 ...............................................................................................................533
附錄D MIME 類型 ........................................................................................................................557
附錄E Base-64 編碼 ....................................................................................................................603
附錄F 摘要認證 .............................................................................................................................607
附錄G 語言標記 ............................................................................................................................615
附錄H MIME 字符集注冊錶.......................................................................................................641
索引 ......................................................................................................................................................661
· · · · · · (
收起)