tags:

views:

52

answers:

2

Yesterday I asked about serving byte ranges from PHP. Today my question is - how should I set Content-Type and Content-Disposition headers when serving several requested byte ranges? Should I repeat them for every byte range or should I just output them once at the beginning? Or maybe I shouldn't output them at all because the client should already know what it is asking?

+1  A: 

Generally, the HTTP response headers should be the same (repeated) if you return the entire resource or just a portion of it; except of course for the Content-Range header which will vary.

Remember that HTTP is stateless, so every response should be complete and able to stand on its own. If serving byte ranges, you really should also be using entity tags (ETags); so that there is no chance that a client could request and get two separate byte ranges that really belong to different revisions of the same resource.

Deron Meranda
ETag's are not an issue in my case - the content will never change.
Vilx-
+1  A: 

Have a look at RFC 2616 (Sections 14.16 and 19.2 in particular). If the client requests a single byte range, the response must contain a single byte range, and the Content-Type and Content-Disposition header values do not change behavior (they should reflect the type of the file being served). However, if the client requests multiple byte ranges in a single request, the response must use a Content-Type of "multipart/byteranges" instead, and each part inside the body specifies its own Content-Type header.

Remy Lebeau - TeamB
OK, and what about content-disposition?
Vilx-
Content-Disposition applies to the entire response as a whole, not to individiual range parts. I don't suggest you include it in your responses unless you are serving up an entire file, since the only defined use of Content-Disposition right now is to specify a filename, which is not very meaningful to byte ranges.
Remy Lebeau - TeamB