what is relation between content-length and byte ranges in HTTP/1.1?

user349026 picture user349026 · Feb 19, 2011 · Viewed 14.2k times · Source

I am not grasping the idea behind content-length and byte ranges as specified by HTTP 1.1 Is there are connection between the two of some sort? If a client requests in terms of byte ranges, say 0-100 out of 200, will the first response contain the "content-length" equal to 100 bytes followed by 100 actual data?

Thanks

Answer

Gumbo picture Gumbo · Feb 19, 2011

The Content-Length entity-header field indicates the size of the entity-body […] sent to the recipient […]

In a non-multipart message the entity-body is the body of the HTTP message as it only contains one entity. So the Content-Length value indicates the length of the message body that is sent and not the size of the whole resource.

So for a partial content response on a 0-100 byte range request (first byte and last byte inclusive) the Content-Length of the response will be 0 ≤ size ≤ 101.

In case of a 12345 byte long resource the response could look like this:

HTTP/1.1 206 Partial Content
Content-Range: bytes 0-100/12345
Content-Length: 101

… 101 bytes of content …