DevKits

Content · Request & Response

Content-Length

The size of the body in bytes.

What is Content-Length?

Content-Length declares the exact size of the message body in bytes. Clients use it to allocate a buffer, show progress bars, and know when the body ends when connection reuse (keep-alive) is in play.

Typical usage

Set automatically by web servers. Only manually set when writing raw HTTP.

Examples

Content-Length: 348

Common gotchas

Content-Length is mutually exclusive with Transfer-Encoding: chunked. Sending both is an HTTP protocol error.

Specification

RFC 9110 §8.6

Frequently asked questions

What is the Content-Length HTTP header?

Content-Length declares the exact size of the message body in bytes. Clients use it to allocate a buffer, show progress bars, and know when the body ends when connection reuse (keep-alive) is in play.

Is Content-Length a request or response header?

Content-Length can appear on both requests and responses. Set automatically by web servers. Only manually set when writing raw HTTP.

What does a Content-Length header look like?

A typical Content-Length header looks like: Content-Length: 348.

What are common mistakes with Content-Length?

Content-Length is mutually exclusive with Transfer-Encoding: chunked. Sending both is an HTTP protocol error.

Related headers

Work with this header