问题
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.
回答1:
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.
回答2:
The answer to the question 'How would I get the same behavior in Firefox as I have in Chrome?' is to upgrade to Firefox 57.0 (Quantum). This version of Firefox (in tests of my own server code, which does the same limiting of partial response size) is able to make requests for additional partial content as the video plays, in much the same way as Chrome and IE.
Having said that, if I seek backwards in the video, Firefox will play a portion of the content from the new position (presumably using the cached partial content for that position) but then fails to request (or use cached) partial content when the buffered content runs out - instead it jumps to the end.
It looks like the Firefox developers made a stab at fixing the issue of smaller-than-expected partial content, but have not got it quite right with respect to seeking and/or caching.
I would be interested to know where in the Firefox source was the original comment about "what to do", to find out what has actually been done and perhaps provide appropriate feedback to the Firefox developers.
来源:https://stackoverflow.com/questions/36114598/how-to-make-browser-request-smaller-range-with-206-partial-content