Content-Length
Request & response Content

Overview

Content-Length states the size of the message body as a decimal number of bytes. The receiver uses it to know exactly how far to read the body — that is, the message boundary.

Details

The value must be the byte count of the body actually transmitted (after any compression/encoding), not a character count (multibyte characters take several bytes). Servers use it for progress indicators, connection reuse, and buffer allocation. A value that disagrees with the real body length causes dropped connections or truncated responses.

When the body size isn't known in advance and must be streamed, use `Transfer-Encoding: chunked` instead of Content-Length. Sending both is forbidden; in HTTP/1.1, when both appear, servers and proxies may interpret them differently — the classic cause of request smuggling.

A server may return 411 Length Required to reject a request body lacking Content-Length, or 413 Content Too Large (Payload Too Large) when the body exceeds an allowed limit.

Syntax

Content-Length: <decimal-byte-count>

e.g. Content-Length: 348

Notes

Related headers

Related status codes

Specification