一、介紹(introduction)
1. 目的——HTTP/0.9-〉HTTP/1.0-〉HTTP/1.1
2. 要求——MUST、REQUIRED、SHOULD
3.
術(shù)語——連接(Connection)、消息(Message)、請求(Request)、應(yīng)答(Response)、資源(Resource)、實(shí)體
(Entity)、表示方法(Representation)、內(nèi)容協(xié)商(Content
Negotiation)、變量(Variant)、客戶機(jī)(Client)、用戶代理(User
agent)、服務(wù)器(Server)、原服務(wù)器(Origin server)、代理服務(wù)器(
Proxy)、網(wǎng)關(guān)(gateway)、高速緩存(Cache)、可緩存(Cacheable)、直接(first-hand)、明確終止時間
(explicit expiration time)、探索終止時間(heuristic expiration
time)、年齡(Age)、保鮮壽命(Freshness
lifetime)、保鮮(Fresh)、陳舊(Stale)、語義透明(semantically
transparent)、有效性判別器(Validator)、實(shí)體標(biāo)記(entity tag)或最終更改時間(Last-Modified
time))、上游/下游(upstream/downstream)、向內(nèi)/向外(inbound/outbound)
4. 總體操作——請求/應(yīng)答、中介
二、符號慣例與一般語法(notational conversions and generic grammar)
1. 擴(kuò)充BNF——name = definition,"literal",rule1 | rule2,(rule1 rule2),*rule,[rule],N rule, #rule,; comment, implied *LWS
2. 基本規(guī)則——OCTET,CHAR,UPALPHA,LOALPHA,ALPHA,DIGIT,CTL,CR,LF,SP,HT,<">
三、協(xié)議參數(shù)(protocol parameters)
1. HTTP版本——HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT
2. 統(tǒng)一資源標(biāo)示符(URI)——統(tǒng)一資源定位器(URL)和統(tǒng)一資源名稱(URN)的結(jié)合,http_URL = "http:" "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. 字符集——本文檔中的術(shù)語"字符集"指一種用一個或更多表格將一個八字節(jié)序列轉(zhuǎn)換成一個字符序列的方法,
charset=token
失蹤字符集
5. 內(nèi)容編碼——內(nèi)容編碼主要用來允許文檔壓縮(信源編碼)
content-coding= token
注冊表包含下列標(biāo)記:gzip,compress,deflate,identity
6. 傳輸編碼——目的是能夠確保通過網(wǎng)絡(luò)安全傳輸(信道編碼)
transfer-coding = "chunked" | transfer-extension
transfer-extension = token *( ";" parameter ),
成塊傳輸代碼
7. 媒體類型——media-type = type "/" subtype *( ";" parameter )
type = token
subtype = token
規(guī)范化和原文缺省
多部分類型
8. 產(chǎn)品標(biāo)記——product = token ["/" product-version]
product-version = token
9. 質(zhì)量值——qvalue = ( "0" [ "." 0*3DIGIT ] )| ( "1" [ "." 0*3("0") ] )
10. 語言標(biāo)記——language-tag = primary-tag *( "-" subtag )
primary-tag = 1*8ALPHA
subtag = 1*8ALPHA
11. 實(shí)體標(biāo)記——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頭域包括常規(guī)頭,請求頭,應(yīng)答頭和實(shí)體頭域
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. 常規(guī)頭域——general-header = Cache-Control| Connection| Date| Pragma| Transfer-Encoding
五、 請求(request)
首行包括利用資源的方式,區(qū)分資源的標(biāo)識,以及協(xié)議的版本號
Request = Request-Line * (( general-header| request-header| entity-header ) CRLF) CRLF [ message-body ]
1. 請求行——Request-Line = Method SP Request-URI SP HTTP-Version CRLF
方法——方法標(biāo)記指的是在請求URI所指定的資源上所實(shí)現(xiàn)的方式
Method = "OPTIONS"| "GET"| "POST"| "PUT"| "DELETE"| "TRACE"| "CONNECT"| extension-method
extension-method = token
請求URL——請求URL是一種全球統(tǒng)一的應(yīng)用于資源請求的資源標(biāo)識符
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和主機(jī)報(bào)頭域所決定
3. 請求報(bào)頭域——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
六、 應(yīng)答(response)
接收和翻譯一個請求信息后,服務(wù)器發(fā)出一個HTTP應(yīng)答信息
Response = Status-Line*(( general-header| response-header| entity-header ) CRLF) CRLF [ message-body ]
1. 狀態(tài)行——Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
狀態(tài)碼——狀態(tài)碼是試圖理解和滿足請求的三位數(shù)字的整數(shù)碼,1xx,2xx,3xx,4xx,5xx,100-〉505-〉擴(kuò)展碼
2. 應(yīng)答報(bào)頭域——response-header = Accept-Ranges| Age| Location| Proxy-Authenticate| Retry-After| Server| Vary| WWW-Authenticate
七、 實(shí)體(entity)
在未經(jīng)特別規(guī)定的情況下,請求與應(yīng)答的消息也可以傳送實(shí)體。 實(shí)體包括實(shí)體報(bào)頭域與實(shí)體正文,而有些應(yīng)答只包括實(shí)體報(bào)頭。
1. 實(shí)體報(bào)頭域——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. 實(shí)體正文——entity-body = *OCTET
entity-body := Content-Encoding( Content-Type( data ) )
八、 連接(connection)
1. 持續(xù)連接——優(yōu)點(diǎn)
持續(xù)連接是任何HTTP連接的缺省方式,支持持續(xù)連接的客戶機(jī)可以以流水線方式發(fā)送請求
代理服務(wù)器
2. 消息傳遞要求——持續(xù)連接與流量控制
監(jiān)視連接中出錯狀態(tài)的消息
100號狀態(tài)的用途
服務(wù)器過早關(guān)閉連接時客戶機(jī)的動作
九、 方法定義(method definitions)
1. 安全和等冪方法
安全方法——GET和HEAD方法除了補(bǔ)救外不應(yīng)該有別的采取措施的含義
等冪方法——沒有副作用的序列是等冪的
2. OPTIONS——OPTIONS方法代表在請求URI確定的請求/應(yīng)答過程中通信條件是否可行的信息
3. GET——GET方法說明了重建信息的內(nèi)容由請求URI來確定
4. HEAD——除了應(yīng)答中禁止返回消息正文外,HEAD方法與GET方法一樣
5. POST——POST方法實(shí)現(xiàn)的實(shí)際功能取決于服務(wù)器
6. PUT——PUT方法要求所附實(shí)體存儲在提供的請求URI下
7. DELETE——DELELE方法要求原服務(wù)器釋放請求URI指向的資源
8. TRACE——TRACE方法用于調(diào)用遠(yuǎn)程的應(yīng)用層循環(huán)請求消息
9. CONNECT——CONNECT方法用于能動態(tài)建立起隧道的代理服務(wù)器
十、 狀態(tài)碼定義(status code definitions)
1. 信息1XX——
100繼續(xù)
101轉(zhuǎn)換協(xié)議
2. 成功2XX——
200請求成功
201創(chuàng)建
202接受
203非權(quán)威信息
204無內(nèi)容
205重置內(nèi)容
206局部內(nèi)容
3. 重新定向3XX——
300多樣選擇
301永久移動
302創(chuàng)立
303觀察別的部分
304只讀
306(沒有用的)
307臨時重發(fā)
4. 客戶錯誤4xx——
400壞請求
401未授權(quán)的
402必需的支付
403禁用
404沒有找到
405不被允許的方法
406不接受
407代理服務(wù)器認(rèn)證所必需
408請求超時
409沖突
410停止
411必需的長度
412預(yù)處理失敗
413請求實(shí)體太大
414請求的URI過長
415不被支持的媒體類型
416請求范圍不滿足
417期望失敗
5. 服務(wù)器錯誤5xx——
500服務(wù)器內(nèi)部錯誤
501不能實(shí)現(xiàn)
502壞網(wǎng)關(guān)
503難以獲得的服務(wù)
504網(wǎng)關(guān)超時
505 HTTP版本不支持
十一、 訪問驗(yàn)證(access authentication)——可選擇
十二、 內(nèi)容談判(content negotiation)
HTTP為了"內(nèi)容談判"提供了一些機(jī)制,即當(dāng)有很多種可能的表示時如何選擇對于一個請求的最佳的表示。
1. 服務(wù)器驅(qū)動談判——一個請求的最佳表示的選擇由服務(wù)器提供的運(yùn)算法則來完成
2. 代理驅(qū)動談判——對于一個應(yīng)答的最佳表示法的選擇是在代理從原服務(wù)器端收到最初的應(yīng)答后實(shí)現(xiàn)的
3. 透明談判——透明的判斷是服務(wù)器驅(qū)動和代理驅(qū)動談判的結(jié)合體
十三、 HTTP中的緩存(caching in HTTP)
HTTP典型應(yīng)用于能通過采用緩存技術(shù)而提高性能的分布式信息系統(tǒng)
1. 緩存——
緩存正確性
警告信息
緩存控制機(jī)制
直接的用戶代理警告
規(guī)則和警告的例外情況
由客戶控制的行為
2. 過期模型——
服務(wù)器指定模型
啟發(fā)式過期
年齡計(jì)算
過期計(jì)算
澄清過期值
澄清多重響應(yīng)
3. 確認(rèn)模型——當(dāng)緩存器想要用一個失時效的條目來相應(yīng)客戶的請求,他首先必須向源服務(wù)器檢驗(yàn)這一緩存條目是否仍然可用
最后修改日期
標(biāo)簽緩存確認(rèn)器
強(qiáng)弱控制器
關(guān)于何時使用實(shí)體標(biāo)簽和最后修改時間的規(guī)則
不確認(rèn)條件
4. 響應(yīng)的緩存能力——除非被明確限制,緩存系統(tǒng)可以將一成功的響應(yīng)作為緩存實(shí)體一直存儲
5. 從緩存構(gòu)造響應(yīng)——
端到端和Hop-by-hop報(bào)頭
不可更改報(bào)頭
聯(lián)合報(bào)頭
聯(lián)合字節(jié)范圍
6. 緩存談判響應(yīng)
7. 共享與非共享緩存
8. 錯誤和不完全響應(yīng)緩存行為
9. GET和 HEAD的副作用
10. 刷新或刪除后的無效性
11. 強(qiáng)制寫通過
12. 緩存替換
13. 歷史紀(jì)錄
十四、 報(bào)頭域定義(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 ) ]
什么是可緩存的
哪些可能被緩存保存
對基本過期失效機(jī)制的改進(jìn)
緩存重新確認(rèn)有效和重載控制
不得轉(zhuǎn)換的指令
緩存控制擴(kuò)展
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
沒有時鐘的原服務(wù)器的運(yùn)作
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: webmaster@w3.org
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
30. Location ——Location = "Location" ":" absoluteURI
Location: http://www.w3.org/pub/WWW/People.html
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——字節(jié)范圍
范圍檢索請求
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. 個人信息
服務(wù)器日志信息的濫用
敏感信息的傳輸
URI中敏感信息的編碼
連接到Accept報(bào)頭的機(jī)要問題
2. 基于文件和路徑名稱的攻擊
3. DNS欺騙
4. Location(位置)報(bào)頭和欺騙
5. 內(nèi)容傾向問題
6. 鑒定證書和空閑的客戶機(jī)
7. 代理服務(wù)器和高速緩存
對代理服務(wù)器的拒絕服務(wù)攻擊
十六、 感謝
十七、 參考文獻(xiàn)
十八、 作者地址
十九、 附錄
文章轉(zhuǎn)自:http://www.cppblog.com/woaidongmao/archive/2008/05/28/51408.html