Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Content-Length and Content-Encoding

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

like image 629
Matt Joiner Avatar asked Mar 24 '16 06:03

Matt Joiner


People also ask

What is HTTP content encoding?

Content encoding is mainly used to compress the message data without losing information about the origin media type. Note that the original media/content type is specified in the Content-Type header, and that the Content-Encoding applies to the representation, or "coded form", of the data.

What is HTTP content Length?

14.13 Content-Length 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.

Is content Length required in HTTP?

The Content-Length is optional in an HTTP request. For a GET or DELETE the length must be zero. For POST, if Content-Length is specified and it does not match the length of the message-line, the message is either truncated, or padded with nulls to the specified length.

Why is content Length important in HTTP?

HTTP Content-Length entity-header is used to indicate the size of entity-body in decimal no of octets i.e. bytes and sent it to the recipient. It is a forbidden header name. Basically it is the number of bytes of data in the body of the request or response. The body comes after the blank line below the headers.


1 Answers

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.

like image 56
Amadan Avatar answered Oct 25 '22 03:10

Amadan