【问题标题】:Content-Length gives size of entire file for first Partial Content responseContent-Length 给出第一个 Partial Content 响应的整个文件的大小
【发布时间】:2018-07-09 01:09:03
【问题描述】:

我在 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的长度?那么客户端怎么知道响应体的长度呢?

【问题讨论】:

    标签: http


    【解决方案1】:

    最简单的解释是 Content-Length 确实是正确的,但是 Firefox 在 ~54MB 之后会中止读取操作。

    【讨论】:

      猜你喜欢
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      • 2013-09-25
      • 2011-11-06
      • 2015-04-05
      • 1970-01-01
      • 1970-01-01
      • 2020-07-15
      相关资源
      最近更新 更多