在收到206具有指定内容范围的Firefox之后,Firefox将不再请求其他数据 [英] Firefox won't request further data after receiving 206 with specified content range

查看:67
本文介绍了在收到206具有指定内容范围的Firefox之后,Firefox将不再请求其他数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了提供一些背景信息,我有一个< video> 标记,该标记具有一个 src 属性,该属性指向我的node.js服务器上的方法.该方法从另一个服务器获取 mp4 文件,或者更确切地说是 mp4 文件的 part ,具体取决于 Range 浏览器指定的HTTP标头,例如- Range:bytes = 0-.

To give some context, I have a <video> tag that has a src attribute that points to a method on my node.js server. That method gets an mp4 file from another server, or rather part of an mp4 file, depending on the Range HTTP header specified by the browser, for example - Range:bytes=0-.

预期的行为(Chrome行为)

为了防止我的node.js服务器从第三方服务器下载整个文件,我实现了大约5MB的最大缓冲区,可以一次下载.因此,如果用户发送请求以获取带有标头的视频

To prevent my node.js server from downloading the entire file from the third party server, I have implemented a max buffer of around 5MB to download at one time. So if the the user sends a request with to fetch the video with the headers

GET /play-test/videoId HTTP/1.1
Host: 127.0.0.1:8000
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept-Encoding: identity;q=1, *;q=0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36
Accept: */*
Referer: http://127.0.0.1:8000/movie/99861
Accept-Language: en-US,en;q=0.8,es;q=0.6
Range: bytes=0-

..然后我的服务器将以

..then my server will respond with

HTTP/1.1 206 Partial Content
X-Powered-By: Express
Content-Range: bytes 0-5000000/415473786
Connection: keep-alive
Accept-Ranges: bytes
Content-Length: 5000001
Content-Type: video/mp4
Date: Tue, 20 Oct 2015 12:50:42 GMT

我认为,这是一个足够常见的模式-尽管客户端(在这种情况下,是浏览器)已请求请求 bytes = 0-(从开始到结束),但我却做出了回应前5MB,最重要的是告诉客户端,响应只包含了415MB中的5MB( Content-Range:字节0-5000000/415473786 ).响应的状态也为 206 ,表明该响应是部分响应.

This, I believe, is a common enough pattern - although the client (in this case, the browser) has requested has requested bytes=0- (start to end), I have instead responded with the first 5MB and most importantly told the client that response contains only those 5MB out of a total of 415MB (Content-Range: bytes 0-5000000/415473786). The response is also has a status of 206 indicating that the response is a partial one.

在Chrome中,它可以按预期的方式工作-在视频播放完前5MB视频之前,它会向同一端点发出另一个请求,但带有标头

In Chrome, this works as expected - just before the video has finished playing the first 5MB of video it makes another request to the same endpoint but with the headers

GET /play-test/videoId HTTP/1.1
Host: 127.0.0.1:8000
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept-Encoding: identity;q=1, *;q=0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36
Accept: */*
Referer: http://127.0.0.1:8000/movie/99861
Accept-Language: en-US,en;q=0.8,es;q=0.6
Range: bytes=5000001-

我再次回复最大5MB ...

Again I respond with the maximum 5MB...

HTTP/1.1 206 Partial Content
X-Powered-By: Express
Content-Range: bytes 5000001-10000001/415473786
Connection: keep-alive
Accept-Ranges: bytes
Content-Length: 5000001
Content-Type: video/mp4
Date: Tue, 20 Oct 2015 12:51:08 GMT

此模式一直持续到视频结束为止,用户使用搜索栏暂停或跳过,在这种情况下,浏览器会在所需的时间内请求特定的字节范围.正如我所说的,所有这些在Chrome中都可以正常运行.

This pattern continues until the video ends, the user pauses or skips using the seek bar, in which case the browser request a specific byte range for the time required. As I said, all works well in Chrome.

Firefox行为

描述Firefox的行为比描述正确的行为更直接!

Describing Firefox's behaviour is much more straight-forward that describing the correct behaviour!

Firefox请求

Host: 127.0.0.1:8000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:41.0) Gecko/20100101 Firefox/41.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
Range: bytes=0-
Referer: http://127.0.0.1:8000/movie/272
Connection: keep-alive

响应

206 Partial Content
Accept-Ranges: bytes
Connection: keep-alive
Content-Length: 5000001
Content-Range: bytes 0-5000000/415473786
Content-Type: video/mp4
Date: Tue, 20 Oct 2015 13:15:49 GMT
X-Powered-By: Express

然后就这样-Firefox播放前5MB的视频,并且不再向服务器发出任何请求.搜索栏显示正确的视频时长,但是搜索栏不起作用.当用户尝试查找视频时,视频会跳回开头并再次播放前5MB.

Then that's it - Firefox plays the first 5MB of video and the no further requests are made to the server. The seek bar displays the correct duration of the video but the seek bar is non-functional. When the user attempts to seek the video skips back to the beginning and plays the first 5MB again.

任何帮助将不胜感激.

推荐答案

客户端(在这种情况下,是浏览器)已请求请求字节= 0-(从开始到结束),而我则以第一个5MB作为响应

the client (in this case, the browser) has requested has requested bytes=0- (start to end), I have instead responded with the first 5MB

我认为那是您的问题.规范说,当客户端要求范围为 0-时,您应该返回整个可用字节范围.您未遵循规范,因此为何不起作用.

I think that's your problem right there. The spec says that you should return the entire available byte range when a client ask for a range of 0-. You're not following the spec, hence why it doesn't work.

这篇关于在收到206具有指定内容范围的Firefox之后,Firefox将不再请求其他数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆