Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make browser request smaller range with 206 Partial Content

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-

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

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.

like image 210
John Smith Avatar asked Mar 20 '16 13:03

John Smith


1 Answers

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).

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.

like image 184
John Smith Avatar answered Sep 28 '22 18:09

John Smith