2011-11-28 83 views
82

是否有可能向我演示範圍請求的示例http會話。 我的意思是什麼是請求和響應頭?樣本http範圍請求會話

+2

幾個月前新發布了HTTP/1.1標準版本。它有一個特殊的RFC範圍請求,這是比舊規範更可讀,包括許多項目的例子:https://tools.ietf.org/html/rfc7233 – Thirler

回答

128

以下是Chrome和靜態Web服務器之間的交換,檢索MP4視頻。

初始請求 - 視頻。注意Accept-Ranges響應頭指示服務器範圍頭支持:在以前的響應

GET /BigBuckBunny_320x180.mp4 
     Cache-Control: max-age=0 
     Connection: keep-alive 
     Accept-Language: en-GB,en-US,en 
     Host: localhost:8080 
     Range: 
     Accept: text/html,application/xhtml+xml,application/xml,*/* 
     User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.7 ... 
     Accept-Encoding: gzip,deflate,sdch 
     Accept-Charset: ISO-8859-1,utf-8,* 
200 OK 
     Content-Type: video/mp4 
     Connection: keep-alive 
     Last-Modified: Wed,14 Dec 2011 15:50:59 GMT 
     ETag: A023EF02BD589BC472A2D6774EAE3C58 
     Transfer-Encoding: 
     Content-Length: 64657027 
     Accept-Ranges: bytes 
     Server: Brisket/1.0.1 
     Date: Wed,14 Dec 2011 16:11:24 GMT 

Range頭檢測 - 用開放式的範圍內後續請求確認支持。響應返回206個狀態和Content-Range頭,以指示存在於所述響應體中的字節數:

GET /BigBuckBunny_320x180.mp4 
     Connection: keep-alive 
     Accept-Language: en-GB,en-US,en 
     Host: localhost:8080 
     Range: bytes=0- 
     Accept: */* 
     User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.7 ... 
     Referer: http://localhost:8080/BigBuckBunny_320x180.mp4 
     Accept-Encoding: identity 
     Accept-Charset: ISO-8859-1,utf-8,* 
206 Partial Content 
     Content-Type: video/mp4 
     Connection: keep-alive 
     Last-Modified: Wed,14 Dec 2011 15:50:59 GMT 
     ETag: A023EF02BD589BC472A2D6774EAE3C58 
     Transfer-Encoding: 
     Content-Length: 64657027 
     Accept-Ranges: bytes 
     Server: Brisket/1.0.1 
     Date: Wed,14 Dec 2011 16:11:25 GMT 
     Content-Range: bytes 0-64657026/64657027 

隨後範圍請求捕捉到文件的結尾(可能以捕獲後的元數據):

GET /BigBuckBunny_320x180.mp4 
     Connection: keep-alive 
     Accept-Language: en-GB,en-US,en 
     Host: localhost:8080 
     Range: bytes=64312833-64657026 
     Accept: */* 
     If-Range: A023EF02BD589BC472A2D6774EAE3C58 
     User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.7 ... 
     Referer: http://localhost:8080/BigBuckBunny_320x180.mp4 
     Accept-Encoding: identity 
     Accept-Charset: ISO-8859-1,utf-8,* 
206 Partial Content 
     Content-Type: video/mp4 
     Connection: keep-alive 
     Last-Modified: Wed,14 Dec 2011 15:50:59 GMT 
     ETag: A023EF02BD589BC472A2D6774EAE3C58 
     Transfer-Encoding: 
     Content-Length: 344194 
     Accept-Ranges: bytes 
     Server: Brisket/1.0.1 
     Date: Wed,14 Dec 2011 16:11:25 GMT 
     Content-Range: bytes 64312833-64657026/64657027 

用戶單擊視頻進度條超出下載範圍 - 發出範圍請求以從選定位置開始播放:

GET /BigBuckBunny_320x180.mp4 
     Connection: keep-alive 
     Accept-Language: en-GB,en-US,en 
     Host: localhost:8080 
     Range: bytes=1073152-64313343 
     Accept: */* 
     If-Range: A023EF02BD589BC472A2D6774EAE3C58 
     User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.7 ... 
     Referer: http://localhost:8080/BigBuckBunny_320x180.mp4 
     Accept-Encoding: identity 
     Accept-Charset: ISO-8859-1,utf-8,* 
206 Partial Content 
     Content-Type: video/mp4 
     Connection: keep-alive 
     Last-Modified: Wed,14 Dec 2011 15:50:59 GMT 
     ETag: A023EF02BD589BC472A2D6774EAE3C58 
     Transfer-Encoding: 
     Content-Length: 63240192 
     Accept-Ranges: bytes 
     Server: Brisket/1.0.1 
     Date: Wed,14 Dec 2011 16:11:25 GMT 
     Content-Range: bytes 1073152-64313343/64657027 
+7

空白的Transfer-Encoding標頭是一個artefact HTTP通信被捕獲的方式,還是有一個真正的HTTP服務器在那裏生成這個頭的空值? – swl10

+7

在第一種情況下,它看起來像服務器返回64657027字節的內容。所以發生了什麼 - 客戶只是丟掉那些內容,然後發出零件的範圍請求真的想要?或者服務器沒有返回任何內容,因爲客戶端消息中的某些內容表示不這麼做。如果是這樣,那是什麼? – Morrie

+2

@Morrie - 它看起來像服務器,知道它本身支持範圍請求,通過「Accept-Ranges:bytes」頭告訴客戶端「我接受範圍請求」,但它也發送資源的內容長度,所以客戶端可以使範圍請求具有上限。就我所知,客戶端消息中沒有任何內容表示這麼做 - 服務器可以選擇以「這裏是整個資源」或「我接受範圍請求」作爲響應 - 這又是「Accept-Ranges」頭的存在。無論如何,這是我的理解。 –