What is the Content-Length header?
The Content-Length header indicates the size of the payload body in decimal number of octets (bytes) sent to the recipient.
API Usage & Best Practices
- Validate request sizing: Gateways check this header to immediately reject payloads exceeding limits with a
413 Content Too Large. - Reject missing lengths only if you must: RFC 9112 lets a server answer a request that has a body but no
Content-Lengthwith411 Length Required, but every HTTP/1.1 recipient must be able to parse chunked bodies, so reserve 411 for a server that genuinely cannot accept a body of unknown length, such as one that has to enforce a size limit before reading. An explicitContent-Length: 0is a valid, empty body rather than a missing header, and shouldn’t trigger 411.
Examples
POST /v1/leads HTTP/1.1Content-Type: application/jsonContent-Length: 124