HTTP: How should I show Content-Type and Content-Disposition when the client requests a byte range?

StackOverflow https://stackoverflow.com/questions/1401529

  •  05-07-2019
  •  | 
  •  

Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top