How to make browser request smaller with 206 partial content

I am currently creating a video streaming service where the video is transcoded in pieces of 1 MB each. The HTML5 player Firefox, Chrome, and IE 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 do not want to return the full content, but only 1 MB of content, so I am returning this:

 Content-Range:bytes 0-1048575/5074944 

Now Chrome accepts this in full and continues to request partial content until it reaches the total length. However, Firefox only makes one request, which contains partial content, not full. Firefox thinks this is full content, and therefore, the full video does not play, only part of it. How do I get the same behavior in Firefox as in Chrome? I tried returning 416 Range not Satisfiable, but both Chrome and Firefox seem to be requesting after receiving this status code.

+5
source share
2 answers

So, I finally gave up on this and took a look at the source code of Firefox. In the place where Firefox gets a different range than expected, the developer asks what to do in this case. The specification does not indicate what to do in this case, and therefore Firefox decided not to do anything. Chrome is a little more creative and came up with what, according to the developers, would be the best answer (this is absolutely the result that I want).

It seems that I'm not the only one with this problem, otherwise I would not have received upvotes. The fact is that for Firefox to fix this problem, we would need to make changes to the specification, which, in my opinion, is almost impossible. Therefore, I close this question and mark this post as an answer.

+1
source

The answer to the question "How do I get the same behavior in Firefox as in Chrome?" consists of upgrading to Firefox 57.0 (Quantum). This version of Firefox (in tests of my own server code that does the same limitation of the partial response size) can make requests for additional partial content as the video plays, much like Chrome and IE.

Having said that, if I search back in the video, Firefox will play back some of the content from a new position (presumably using cached partial content for that position), but then cannot request (or use cached) partial content when the buffer content ends - instead he skips to the end.

It seems that Firefox developers have dealt a blow to fix the problem of smaller than expected partial content, but have not gotten the full rights regarding search and / or caching.

I would be interested to know where in the Firefox source there was an original β€œwhat to do” comment, to find out what was actually done, and possibly provide relevant feedback to the Firefox developers.

-1
source

Source: https://habr.com/ru/post/1245420/


All Articles