1. 程式人生 > >HTTP/1.1協議規範(中文歸納版)

HTTP/1.1協議規範(中文歸納版)

一、介紹(introduction)

1. 目的——HTTP/0.9-〉HTTP/1.0-〉HTTP/1.1

2. 要求——MUST、REQUIRED、SHOULD

3. 術語——連線(Connection)、訊息(Message)、請求(Request)、應答(Response)、資源(Resource)、實體(Entity)、表示方法(Representation)、內容協商(Content Negotiation)、變數(Variant)、客戶機(Client)、使用者代理(User agent)、伺服器(Server)、原伺服器(Origin server)、代理伺服器( Proxy)、閘道器(gateway)、快取記憶體(Cache)、可快取(Cacheable)、直接(first-hand)、明確終止時間(explicit expiration time)、探索終止時間(heuristic expiration time)、年齡(Age)、保鮮壽命(Freshness lifetime)、保鮮(Fresh)、陳舊(Stale)、語義透明(semantically transparent)、有效性判別器(Validator)、實體標記(entity tag)或最終更改時間(Last-Modified time))、上游/下游(upstream/downstream)、向內/向外(inbound/outbound)

4. 總體操作——請求/應答、中介

二、符號慣例與一般語法(notational conversions and generic grammar)

1. 擴充BNF——name = definition,"literal",rule1 | rule2,(rule1 rule2),*rule,[rule],N rule, #rule,; comment, implied *LWS

2. 基本規則——OCTET,CHAR,UPALPHA,LOALPHA,ALPHA,DIGIT,CTL,CR,LF,SP,HT,<">

三、協議引數(protocol parameters)

1. HTTP版本——HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT

2. 統一資源標示符(URI)——統一資源定位器(URL)和統一資源名稱(URN)的結合,http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]

3. 日期/時間格式——Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123,
Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036,
Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format

4. 字符集——本文件中的術語"字符集"指一種用一個或更多表格將一個八位元組序列轉換成一個字元序列的方法,
charset=token
失蹤字符集

5. 內容編碼——內容編碼主要用來允許文件壓縮(信源編碼)
content-coding= token
登錄檔包含下列標記:gzip,compress,deflate,identity

6. 傳輸編碼——目的是能夠確保通過網路安全傳輸(通道編碼)
transfer-coding = "chunked" | transfer-extension
transfer-extension = token *( ";" parameter ),
成塊傳輸程式碼

7. 媒體型別——media-type = type "/" subtype *( ";" parameter )
type = token
subtype = token
規範化和原文預設
多部分型別

8. 產品標記——product = token ["/" product-version]
product-version = token

9. 質量值——qvalue = ( "0" [ "." 0*3DIGIT ] )| ( "1" [ "." 0*3("0") ] )

10. 語言標記——language-tag = primary-tag *( "-" subtag )
primary-tag = 1*8ALPHA
subtag = 1*8ALPHA

11. 實體標記——entity-tag = [ weak ] opaque-tag
weak = "W/"
opaque-tag = quoted-string

12. 範圍單位——range-unit = bytes-unit | other-range-unit
bytes-unit = "bytes"
other-range-unit = token

四、 HTTP訊息(HTTP message)

1. 訊息型別——HTTP-message = Request | Response ; HTTP/1.1 messages
generic-message = start-line *(message-header CRLF) CRLF [ message-body ]
start-line = Request-Line | Status-Line

2. 訊息頭——HTTP頭域包括常規頭,請求頭,應答頭和實體頭域
message-header = field-name ":" [ field-value ]
field-name = token
field-value = *( field-content | LWS )
field-content = <the OCTETs making up the field-value and consisting of either *TEXT or combinations of token, separators, and quoted-string>

3. 訊息體——message-body = entity-body| <entity-body encoded as per Transfer-Encoding>

4. 訊息的長度——決定因素

5. 常規頭域——general-header = Cache-Control| Connection| Date| Pragma| Transfer-Encoding

五、 請求(request)

首行包括利用資源的方式,區分資源的標識,以及協議的版本號
Request = Request-Line * (( general-header| request-header| entity-header ) CRLF) CRLF [ message-body ]

1. 請求行——Request-Line = Method SP Request-URI SP HTTP-Version CRLF
方法——方法標記指的是在請求URI所指定的資源上所實現的方式
Method = "OPTIONS"| "GET"| "POST"| "PUT"| "DELETE"| "TRACE"| "CONNECT"| extension-method
extension-method = token
請求URL——請求URL是一種全球統一的應用於資源請求的資源識別符號
Request-URI = "*" | absoluteURI | abs_path | authority
請求行舉例:GET http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1
GET /pub/WWW/TheProject.html HTTP/1.1
Host: www.w3.org

2. 請求定義的資源——一個INTERNET請求所定義的精確資源由請求URL和主機報頭域所決定

3. 請求報頭域——request-header = Accept| Accept-Charset| Accept-Encoding| Accept-Language| Authorization| Expect| From| Host| If-Match| If-Modified-Since| If-None-Match| If-Range| If-Unmodified-Since| Max-Forwards| Proxy-Authorization| Range| Referer| TE| User-Agent

六、 應答(response)

接收和翻譯一個請求資訊後,伺服器發出一個HTTP應答資訊
Response = Status-Line*(( general-header| response-header| entity-header ) CRLF) CRLF [ message-body ]

1. 狀態行——Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
狀態碼——狀態碼是試圖理解和滿足請求的三位數字的整數碼,1xx,2xx,3xx,4xx,5xx,100-〉505-〉擴充套件碼

2. 應答報頭域——response-header = Accept-Ranges| Age| Location| Proxy-Authenticate| Retry-After| Server| Vary| WWW-Authenticate

七、 實體(entity)

在未經特別規定的情況下,請求與應答的訊息也可以傳送實體。 實體包括實體報頭域與實體正文,而有些應答只包括實體報頭。

1. 實體報頭域——entity-header = Allow | Content-Encoding| Content-Language| Content-Length | Content-Location| Content-MD5| Content-Range| Content-Type| Expires| Last-Modified| extension-header
extension-header = message-header

2. 實體正文——entity-body = *OCTET
entity-body := Content-Encoding( Content-Type( data ) )

八、 連線(connection)

1. 持續連線——優點
持續連線是任何HTTP連線的預設方式,支援持續連線的客戶機可以以流水線方式傳送請求
代理伺服器

2. 訊息傳遞要求——持續連線與流量控制
監視連線中出錯狀態的訊息
100號狀態的用途
伺服器過早關閉連線時客戶機的動作

九、 方法定義(method definitions)

1. 安全和等冪方法
安全方法——GET和HEAD方法除了補救外不應該有別的採取措施的含義
等冪方法——沒有副作用的序列是等冪的

2. OPTIONS——OPTIONS方法代表在請求URI確定的請求/應答過程中通訊條件是否可行的資訊

3. GET——GET方法說明了重建資訊的內容由請求URI來確定

4. HEAD——除了應答中禁止返回訊息正文外,HEAD方法與GET方法一樣

5. POST——POST方法實現的實際功能取決於伺服器

6. PUT——PUT方法要求所附實體儲存在提供的請求URI下

7. DELETE——DELELE方法要求原伺服器釋放請求URI指向的資源

8. TRACE——TRACE方法用於呼叫遠端的應用層迴圈請求訊息

9. CONNECT——CONNECT方法用於能動態建立起隧道的代理伺服器

十、 狀態碼定義(status code definitions)

1. 資訊1XX——
100繼續
101轉換協議

2. 成功2XX——
200請求成功
201建立
202接受
203非權威資訊
204無內容
205重置內容
206區域性內容

3. 重新定向3XX——
300多樣選擇
301永久移動
302創立
303觀察別的部分
304只讀
306(沒有用的)
307臨時重發

4. 客戶錯誤4xx——
400壞請求
401未授權的
402必需的支付
403禁用
404沒有找到
405不被允許的方法
406不接受
407代理伺服器認證所必需
408請求超時
409衝突
410停止
411必需的長度
412預處理失敗
413請求實體太大
414請求的URI過長
415不被支援的媒體型別
416請求範圍不滿足
417期望失敗

5. 伺服器錯誤5xx——
500伺服器內部錯誤
501不能實現
502壞閘道器
503難以獲得的服務
504閘道器超時
505 HTTP版本不支援

十一、 訪問驗證(access authentication)——可選擇

十二、 內容談判(content negotiation)

HTTP為了"內容談判"提供了一些機制,即當有很多種可能的表示時如何選擇對於一個請求的最佳的表示。

1. 伺服器驅動談判——一個請求的最佳表示的選擇由伺服器提供的運演算法則來完成

2. 代理驅動談判——對於一個應答的最佳表示法的選擇是在代理從原伺服器端收到最初的應答後實現的

3. 透明談判——透明的判斷是伺服器驅動和代理驅動談判的結合體

十三、 HTTP中的快取(caching in HTTP)

HTTP典型應用於能通過採用快取技術而提高效能的分散式資訊系統

1. 快取——
快取正確性
警告資訊
快取控制機制
直接的使用者代理警告
規則和警告的例外情況
由客戶控制的行為

2. 過期模型——
伺服器指定模型
啟發式過期
年齡計算
過期計算
澄清過期值
澄清多重響應

3. 確認模型——當快取器想要用一個失時效的條目來相應客戶的請求,他首先必須向源伺服器檢驗這一快取條目是否仍然可用
最後修改日期
標籤快取確認器
強弱控制器
關於何時使用實體標籤和最後修改時間的規則
不確認條件

4. 響應的快取能力——除非被明確限制,快取系統可以將一成功的響應作為快取實體一直儲存

5. 從快取構造響應——
端到端和Hop-by-hop報頭
不可更改報頭
聯合報頭
聯合位元組範圍

6. 快取談判響應

7. 共享與非共享快取

8. 錯誤和不完全響應快取行為

9. GET和 HEAD的副作用

10. 重新整理或刪除後的無效性

11. 強制寫通過

12. 快取替換

13. 歷史紀錄

十四、 報頭域定義(header field definitions)

1. Accept——Accept = "Accept" ":" #( media-range [ accept-params ] )
media-range = ( "*/*"| ( type "/" "*" )| ( type "/" subtype )) *( ";" parameter )
accept-params = ";" "q" "=" qvalue *( accept-extension )
accept-extension = ";" token [ "=" ( token | quoted-string ) ]
例1:Accept: audio/*; q=0.2, audio/basic
例2:Accept: text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c

2. Accept-Charset——Accept-Charset = "Accept-Charset" ":" 1#( ( charset | "*" )[ ";" "q" "=" qvalue ] )
例:Accept-Charset: iso-8859-5, unicode-1-1;q=0.8

3. Accept-Encoding——Accept-Encoding = "Accept-Encoding" ":" 1#( codings [ ";" "q" "=" qvalue ] )
codings = ( content-coding | "*" )
例:Accept-Encoding: gzip;q=1.0, identity; q=0.5, *;q=0

4. Accept-Language——Accept-Language = "Accept-Language" ":" 1#( language-range [ ";" "q" "=" qvalue ] )
language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )
例:Accept-Language: da, en-gb;q=0.8, en;q=0.7

5. Accept-Range——Accept-Ranges = "Accept-Ranges" ":" acceptable-ranges
acceptable-ranges = 1#range-unit | "none"
例:Accept-Ranges: bytes

6. Age——Age = "Age" ":" age-value
age-value = delta-seconds

7. Allow——Allow = "Allow" ":" #Method
例:Allow: GET, HEAD, PUT

8. Authorization——Authorization = "Authorization" ":" credentials

9. Cache-Control——Cache-Control = "Cache-Control" ":" 1#cache-directive
cache-directive = cache-request-directive| cache-response-directive
cache-request-directive ="no-cache"| "no-store"| "max-age" "=" delta-seconds| "max-stale" [ "=" delta-seconds ]| "min-fresh" "=" delta-seconds| "no-transform"| "only-if-cached"| cache-extension
cache-response-directive ="public"| "private" [ "=" <"> 1#field-name <"> ]| "no-cache" [ "=" <"> 1#field-name <"> ]| "no-store"| "no-transform"| "must-revalidate"| "proxy-revalidate"| "max-age" "=" delta-seconds| "s-maxage" "=" delta-seconds| cache-extension
cache-extension = token [ "=" ( token | quoted-string ) ]
什麼是可快取的
哪些可能被快取儲存
對基本過期失效機制的改進
快取重新確認有效和過載控制
不得轉換的指令
快取控制擴充套件

10. Connection——Connection = "Connection" ":" 1#(connection-token)
connection-token = token
例:Connection: close

11. Content-Encoding——Content-Encoding = "Content-Encoding" ":" 1#content-coding
例:Content-Encoding: gzip

12. Content-Language——Content-Language = "Content-Language" ":" 1#language-tag
例:Content-Language: mi, en

13. Content-Length——Content-Length = "Content-Length" ":" 1*DIGIT
Content-Length: 3495

14. Content-Location——Content-Location = "Content-Location" ":"( absoluteURI | relativeURI )

15. Content-MD5——Content-MD5 = "Content-MD5" ":" md5-digest
md5-digest = <base64 of 128 bit MD5 digest as per RFC 1864>

16. Content-Range——Content-Range = "Content-Range" ":" content-range-spec
content-range-spec = byte-content-range-spec
byte-content-range-spec = bytes-unit SP byte-range-resp-spec "/"( instance-length | "*" )
byte-range-resp-spec = (first-byte-pos "-" last-byte-pos) | "*"
instance-length = 1*DIGIT
例:The first 500 bytes:bytes 0-499/1234

17. Content-Type——Content-Type = "Content-Type" ":" media-type
例:Content-Type: text/html; charset=ISO-8859-4

18. Date——Date = "Date" ":" HTTP-date
例:Date: Tue, 15 Nov 1994 08:12:31 GMT
沒有時鐘的原伺服器的運作

19. Etag——ETag = "ETag" ":" entity-tag
例:ETag: W/"xyzzy"

20. Expect——Expect = "Expect" ":" 1#expectation
expectation = "100-continue" | expectation-extension
expectation-extension = token [ "=" ( token | quoted-string )*expect-params ]
expect-params = ";" token [ "=" ( token | quoted-string ) ]

21. Expires——Expires = "Expires" ":" HTTP-date
例:Expires: Thu, 01 Dec 1994 16:00:00 GMT

22. From——From = "From" ":" mailbox
例:From: [email protected]

23. Host——Host = "Host" ":" host [ ":" port ] ; Section 3.2.2

24. If-Match——If-Match = "If-Match" ":" ( "*" | 1#entity-tag )
例:If-Match: "xyzzy", "r2d2xxxx", "c3piozzzz"

25. If-Modified-Since——If-Modified-Since = "If-Modified-Since" ":" HTTP-date
例:If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT

26. If-None-Match ——If-None-Match = "If-None-Match" ":" ( "*" | 1#entity-tag )
例:If-None-Match: W/"xyzzy", W/"r2d2xxxx", W/"c3piozzzz"

27. If-Range ——If-Range = "If-Range" ":" ( entity-tag | HTTP-date )

28. If-Unmodified-Since ——If-Unmodified-Since = "If-Unmodified-Since" ":" HTTP-date
例:If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT

29. Last-Modified ——Last-Modified = "Last-Modified" ":" HTTP-date
例:Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT

31. Max-Forwards ——Max-Forwards = "Max-Forwards" ":" 1*DIGIT

32. Pragma ——Pragma = "Pragma" ":" 1#pragma-directive
pragma-directive = "no-cache" | extension-pragma
extension-pragma = token [ "=" ( token | quoted-string ) ]

33. Proxy-Authenticate ——Proxy-Authenticate = "Proxy-Authenticate" ":" 1#challenge

34. Proxy-Authorization ——Proxy-Authorization = "Proxy-Authorization" ":" credentials

35. Range——位元組範圍
範圍檢索請求
Range = "Range" ":" ranges-specifier

36. Referer——Referer = "Referer" ":" ( absoluteURI | relativeURI )

37. Retry-After ——Retry-After = "Retry-After" ":" ( HTTP-date | delta-seconds )

38. Server ——Server = "Server" ":" 1*( product | comment )

39. TE ——TE = "TE" ":" #( t-codings )
t-codings = "trailers" | ( transfer-extension [ accept-params ] )
例:TE: trailers, deflate;q=0.5

40. Trailer ——Trailer = "Trailer" ":" 1#field-name

41. Transfer-Encoding ——Transfer-Encoding = "Transfer-Encoding" ":" 1#transfer-coding
例:Transfer-Encoding: chunked

42. Upgrade——Upgrade = "Upgrade" ":" 1#product
例:Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11

43. User-Agent ——User-Agent = "User-Agent" ":" 1*( product | comment )
例:User-Agent: CERN-LineMode/2.15 libwww/2.17b3

44. Vary ——Vary = "Vary" ":" ( "*" | 1#field-name )

45. Via ——Via = "Via" ":" 1#( received-protocol received-by [ comment ] )
received-protocol = [ protocol-name "/" ] protocol-version
protocol-name = token
protocol-version = token
received-by = ( host [ ":" port ] ) | pseudonym
pseudonym = token
例:Via: 1.0 ricky, 1.1 ethel, 1.1 fred, 1.0 lucy

46. Warning = "Warning" ":" 1#warning-value
warning-value = warn-code SP warn-agent SP warn-text [SP warn-date]
warn-code = 3DIGIT
warn-agent = ( host [ ":" port ] ) | pseudonym
warn-text = quoted-string
warn-date = <"> HTTP-date <">

47. WWW-Authenticate ——WWW-Authenticate = "WWW-Authenticate" ":" 1#challenge

十五、 安全考慮(security considerations)

一些建議,但是並不包括最終解決方案

1. 個人資訊
伺服器日誌資訊的濫用
敏感資訊的傳輸
URI中敏感資訊的編碼
連線到Accept報頭的機要問題

2. 基於檔案和路徑名稱的攻擊

3. DNS欺騙

4. Location(位置)報頭和欺騙

5. 內容傾向問題

6. 鑑定證書和空閒的客戶機

7. 代理伺服器和快取記憶體
對代理伺服器的拒絕服務攻擊

十六、 感謝

十七、 參考文獻

十八、 作者地址

十九、 附錄