This question has been asked quite a few times on StackOverflow and I would like to get an understanding of the concepts and process rather than directly solve a problem. I found the following post where the explanation was nicely detailed but have some follow up questions which I hope someone can elaborate on.

video streaming

The following extract is what I am referring my questions to:

This is however a lot of additional code in your servlet which requires a well understanding of the HTTP Range specification. Usually the servletcontainer's (Tomcat, JBoss AS, Glassfish, etc) own default servlet already supports this out the box. So if there's a way to publish the media folder into the web by standard means, so that you don't need to homegrow a servlet for this, then I'd go on this route.

Here the author explains that a lot of servletcontainers (servlets/webservers I assume) handle the range request specification by returning the specific range request of a video stream response. The software I am working on delivers a static video file stream to a servlet that plays back the video in a Chrome pop-up window. I am reading the video into an inputstream and deliver it as the httpresponse to the request and add the relevant headers like (Content-Range, Content-Length, etc.) which is all done on the webserver or dataserver end. The response is returned to a servlet. Now I am still not sure if I understand this correctly or explained the setup above that it makes sense, but it does work right now as I can see the video playing, am able to seek back and forward and can see the browser debugger where the requests are made back for the next range of bytes.

Am I correct then that the servlet does all the byte range work and I don't have to explicitly rewrite code to only send certain byte ranges in the response? I ask this in hopes of a serious response, because my supervisor insists I need to send the specific byte ranges. My argument was that if this works fine in Firefox, why would I need to rewrite the code completely to render it in Chrome. It only fails in Chrome with large video sizes where after playing most of the video it gives an EofException which my understanding is related to jetty settings and also another error related to a mismatch in expected length of the audio which I send as well.

But back to my question on my interpretation of the way this works; this is someone with 20+ years experience so I have no clue what I am talking about and need to verify if my understanding is correct.


The client and server share responsibility if you're using HTTP requests for partial content:

Whenever the client sends a partial GET request with a Range request header to the server, then server should intercept on the conditional GET request headers (all headers starting with If) and handle accordingly. Whenever the If-Match or If-Unmodified-Since conditions are negative, the server should send a 412 "Precondition Failed" response back without any content. Whenever the If-Range condition is negative, then the server should ignore the Range header and send the full file back. Whenever the Range header is in invalid format, then the server should send a 416 "Requested Range Not Satisfiable" response back without any content.

If a partial GET request with a valid Range header is sent by the client, then the server should send the specific byte range(s) back as a 206 "Partial Content" response.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.