是否可以向我展示带有范围请求的示例http会话。我的意思是请求和响应头是什么?
Answers:
以下是Chrome和静态网络服务器之间的交换,以检索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
检测到先前响应中的范围标头-后续请求具有开放范围以确认支持。响应返回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
Accept-Ranges: bytes
标头告诉客户端“我接受范围请求” ,但是它还会向下发送资源的内容长度,以便客户端可以使用上限值发出范围请求界。据我所知,客户端消息中没有任何内容表明可以执行此操作-服务器可以选择以“这里是整个资源”或“我接受范围请求”进行响应-再次是Accept-Ranges
标头的存在。无论如何,这就是我的理解。