16

Does the HTTP response header Content-Length pertain to the length before or after decoding the body due to Content-Encoding: gzip?

Matt Joiner
  • 112,946
  • 110
  • 377
  • 526

1 Answers1

21

It is raw length of whatever is in the HTTP body. This allows the HTTP client to detect the end of the transmission in cases of persistent connection. Thus, if the body is 10000 bytes pre-compression but 5000 bytes compressed, length is 5000; counting from the end of the header, 5001th byte received will be part of a new HTTP transmission.

Amadan
  • 191,408
  • 23
  • 240
  • 301
  • Can you provide a link to an authoritative source? – Matt Joiner Mar 28 '16 at 00:05
  • 5
    [RFC2616](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13): "The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs ... Applications SHOULD use this field to indicate the **transfer-length** of the message-body, unless this is prohibited by the rules in section [4.4](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4)." (emphasis mine). The exceptions all deal with cases when `Content-Length` header is not applicable. – Amadan Mar 28 '16 at 01:27