Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Content-Range and Range headers?

What is the difference between HTTP headers Content-Range and Range? When should each be used?

I am trying to stream an audio file from a particular byte offset. Should I use Content-Range or Range header?

Thanks

like image 575
lostInTransit Avatar asked Apr 04 '09 07:04

lostInTransit


People also ask

What is content-range header?

The Content-Range HTTP header is a response header that indicates where a partial message belongs in a full body massage. This header is sent with a partial entity-body to specify where in the full entity-body the partial body should be applied.

What are the range of heading?

Heading is typically based on cardinal directions, so 0° (or 360°) indicates a direction toward true north, 90° true east, 180° true south, and 270° true west.

What is content-length in HTTP header?

The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.

Did you declare content-range in the access control expose headers header?

If you are using CORS, did you declare Content-Range in the Access-Control-Expose-Headers header? yes, but the best answer is to solve it inside of rails response.


2 Answers

Actually, the accepted answer is not complete. Content-Range is not only used in responses. It is also legal in requests that provide an entity body.

For example, an HTTP PUT provides an entity body, it might provide only a portion of an entity. Thus the PUT request can include a Content-Range header indicating to the server where the partial entity body should be merged into the entity.

For example, let's first create and then append to a file using HTTP:

Request 1:

PUT /file HTTP/1.1 Host: server Content-Length: 1  a 

Request 2:

PUT /file HTTP/1.1 Host: server Content-Range: bytes 1-2/* Content-Length: 1  a 

How, let's see the file's contents...

Request 3:

GET /file HTTP/1.1 Host: server  HTTP/1.1 200 OK Content-Length: 2  aa 

This allows random file access, both READING and WRITING over HTTP. I just wanted to clarify, as I was researching the use of Content-Range in a WebDAV client I am developing, so perhaps this expanded information will prove useful to somebody else.

like image 55
btimby Avatar answered Sep 23 '22 23:09

btimby


Range is used in the request, to ask for a particular range (or ranges) of bytes. Content-Range is used in the response, to indicate which bytes the server is giving you (which may be different than the range you requested), as well as how long the entire content is (if known).

like image 45
Brian Campbell Avatar answered Sep 23 '22 23:09

Brian Campbell