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

14,544

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 …
Share:
14,544

Related videos on Youtube

Admin
Author by

Admin

Updated on May 21, 2022

Comments

  • Admin
    Admin about 2 years

    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

  • Admin
    Admin over 13 years
    Thanks for clearing it out. Was pretty confusing, the HTTP response you wrote cleared it out nicely!
  • frostymarvelous
    frostymarvelous over 9 years
    helped me solve my issue. android mediaplayer was giving an incorrect duration thanks a bunch.