Kirk Ouimet
Kirk Ouimet

Reputation: 28364

Is the Content-Length header the size in bytes of the compressed or uncompressed bytes?

I'm implementing static file serving in node.js. Let's say I am sending a file called party-time.txt which is:

100 bytes uncompressed

70 bytes gzipped

If I send the file gzipped, should the Content-Length header be 100 or 70?

Upvotes: 8

Views: 1284

Answers (1)

Opal
Opal

Reputation: 84784

Please have a look at the specification. It clearly states:

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.

Digging deeper:

The message-body (if any) of an HTTP message is used to carry the
entity-body associated with the request or response. The message-body differs from the entity-body only when a transfer-coding has been
applied, as indicated by the Transfer-Encoding header field (...)

So, the Content-length is the size of compressed body.

Upvotes: 7

Related Questions