content

Content-Length

Number of octets in the message body, letting the recipient know exactly where the message ends. Required for most requests with bodies unless Transfer-Encoding: chunked is used.

Content-Length: <decimal-octet-count>

Common directives / values

Directive Purpose
0 Explicit empty body — common on POST/PUT with no payload.
<n> Exact byte count of the body; must match reality.
omitted with chunked Do NOT send Content-Length together with Transfer-Encoding: chunked.

Examples

Content-Length: 348

Body is exactly 348 bytes.

Content-Length: 0\nContent-Type: application/json

POST with no body; Content-Length: 0 is preferred to omission.

HTTP/1.1 204 No Content\nContent-Length: 0

204 responses conventionally include Content-Length: 0.

Transfer-Encoding: chunked

Alternative when the length isn't known up front — Content-Length must be absent.

Gotcha

Sending both Content-Length and Transfer-Encoding: chunked is the classic request-smuggling vector (CL.TE / TE.CL); load balancers and origins must agree on parsing. A wrong count silently truncates or hangs the connection.

Related headers

← All HTTP headers · HTTP status codes · Fix CORS errors