如何使用206部分内容使浏览器请求的范围更小 [英] How to make browser request smaller range with 206 Partial Content

查看:91
本文介绍了如何使用206部分内容使浏览器请求的范围更小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在提供视频流服务,该视频将以每个大约1MB的块进行转码.Firefox,Chrome和IE的HTML5播放器都尽力请求部分内容(通过在请求中添加Range标头).不幸的是,大多数情况下,此标头如下所示:

I am currently making a video streaming service where the video is transcoded in chunks of roughly 1MB each. The HTML5 player of Firefox, Chrome and IE all try their best to request partial content (by adding the Range header to their request). Unfortunately, most of the time this header looks like this:

Range:bytes=0-

我不想返回完整的内容,但是只返回1MB的内容,所以我返回:

I don't want to return the full content, but only 1MB of the content, so I return this:

Content-Range:bytes 0-1048575/5074944

现在,Chrome完全接受此要求,并继续要求部分内容,直到达到总长度为止.但是,Firefox仅发出一个包含部分内容而不包含全部内容的请求.Firefox认为这是完整的内容,因此并不是正在播放完整的视频,而只是其中的一部分.我如何在Firefox中获得与Chrome中相同的行为?我尝试返回416 Range not Satisfiable,但Chrome和Firefox在收到此状态代码后似乎都在请求.

Now Chrome accepts this completely and keeps requesting partial content until it has reached the total length. Firefox however makes only one request which contains the partial content and not the full. Firefox thinks it is the full content and thus not the full video is being played, only part of it. How would I get the same behavior in Firefox as I have in Chrome? I tried returning 416 Range not Satisfiable but both Chrome and Firefox seems to requesting after receiving this status code.

推荐答案

所以我最终放弃了这一点,并查看了Firefox的源代码.在Firefox接收到的范围超出预期范围的地方,开发人员会发表评论,询问在这种情况下该怎么做.该规范未指定在这种情况下的处理方法,因此Firefox选择不执行任何操作.Chrome更具创造力,并提出了开发人员认为将是最好的响应(这绝对是我想要的结果).

So I finally gave up on this and had a look at the source code of Firefox. At the place where Firefox receives a different range than expect, a comment is placed by a developer asking what to do in this case. The specification does not specify what to do in such case and so Firefox chose to do nothing. Chrome is a little more creative and came up with what the developers thought would be the best response (which is absolutely the result I want).

似乎我不是唯一一个遇到此问题的人,否则我不会得到投票.问题是:要使Firefox纠正此问题,我们需要对规范进行更改,我认为这几乎是不可能的.因此,我正在关闭此问题并将此帖子标记为答案.

It seems like I am not the only one with this problem, otherwise I wouldn't have gotten upvotes. The thing is: to make Firefox correct this problem we would need to make a change to the specification which I believe to be close to impossible. Therefore I am closing this question and marking this post as the answer.

这篇关于如何使用206部分内容使浏览器请求的范围更小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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