我在Xampp下托管了一个大型(1.8GB)视频文件。我创建了以下HTML文件:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<video controls width="800" src="test01.mp4" />
</body>
</html>
而且(好消息),页面加载后并不会一次全部下载视频-根据需要分批下载视频以播放视频。
但是,我在理解发送的HTTP响应时遇到了麻烦。最初加载页面时,有关视频的前两个HTTP请求是:
GET http://localhost:90/movies/test01.mp4
Host: localhost:90
User-Agent: Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0
Accept: video/webm,video/ogg,video/*;q=0.9,application/ogg;q=0.7,audio/*;q=0.6,*/*;q=0.5
Accept-Language: en-US,en;q=0.5
Referer: http://localhost:90/movies/
Range: bytes=0-
DNT: 1
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
响应头:
HTTP/1.1 206 Partial Content
Date: Mon, 09 Jul 2018 00:16:32 GMT
Server: Apache/2.4.29 (Win32) OpenSSL/1.1.0g PHP/7.2.3
Last-Modified: Fri, 29 Jun 2018 09:00:33 GMT
ETag: "77ab7f58-56fc414a18560"
Accept-Ranges: bytes
Content-Length: 2007727960
Cache-Control: no-cache, must-revalidate
Content-Range: bytes 0-2007727959/2007727960
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: video/mp4
第二个请求标头:
Host: localhost:90
User-Agent: Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0
Accept: video/webm,video/ogg,video/*;q=0.9,application/ogg;q=0.7,audio/*;q=0.6,*/*;q=0.5
Accept-Language: en-US,en;q=0.5
Referer: http://localhost:90/movies/
Range: bytes=1992327168-
DNT: 1
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
第二个响应头:
HTTP/1.1 206 Partial Content
Date: Mon, 09 Jul 2018 00:16:35 GMT
Server: Apache/2.4.29 (Win32) OpenSSL/1.1.0g PHP/7.2.3
Last-Modified: Fri, 29 Jun 2018 09:00:33 GMT
ETag: "77ab7f58-56fc414a18560"
Accept-Ranges: bytes
Content-Length: 15400792
Cache-Control: no-cache, must-revalidate
Content-Range: bytes 1992327168-2007727959/2007727960
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: video/mp4
第一个响应的Content-Length: 2007727960
为1.8 GB。但是,完整的视频无法传输-Firefox的“网络”标签报告传输的数据仅为54.75 MB。
第二个请求然后要求Range: bytes=1992327168-
,这样浏览器就可以知道第一个响应的响应主体长度,即使Content-Length
标头不正确。与第一个响应不同,第二个响应的Content-Length
设置正确。
在第一个请求中,为什么未将Content-Length
设置为响应正文as it should be的长度?然后客户如何知道响应主体有多长时间?
答案 0 :(得分:0)
最简单的解释是Content-Length确实正确,但是Firefox在〜54MB之后中止了读取操作。