Understanding HTTP/1.1 chunked transfer coding
Chunked transfer coding frames an HTTP/1.1 body as size-marked chunks when the total length is not known in advance. A zero-size last chunk marks the end. It is not an application upload protocol that splits one upload into independent requests, and it cannot be used in HTTP/2.
Chunked transfer coding frames an HTTP/1.1 body as size-marked chunks when the total length is not known in advance. A zero-size last chunk marks the end. It is not an application upload protocol that splits one upload into independent requests, and it cannot be used in HTTP/2.
Each chunk contains a hexadecimal size, CRLF, that many octets of data, and another CRLF. A final zero chunk may be followed by trailer fields and an empty line.
HTTP/1.1 200 OK
Transfer-Encoding: chunked
4
Wiki
5
pedia
0Here, 4 and 5 are hexadecimal octet counts. Chunk boundaries are transport framing and need not be preserved for the receiving application. Intermediaries may decode or reapply transfer coding.
Use chunked when the body length is unknown and the connection uses HTTP/1.1. If the length is known, RFC 9112 generally recommends Content-Length. Some servers or gateways still reject chunked requests with 411 Length Required, so check the API and intermediary behavior. A missing zero-size last chunk means the message is incomplete. Receivers must parse hexadecimal sizes safely, prevent integer overflow, and enforce independent size and time limits; chunked itself sets no maximum size and provides no integrity check.
Do not send Content-Length together with Transfer-Encoding: chunked. Conflicting framing can create parsing discrepancies and request-smuggling risk. HTTP/2 carries content in DATA frames and prohibits chunked transfer coding and Transfer-Encoding. Let the HTTP library frame streaming bodies for the negotiated protocol instead of constructing wire chunks in application code.
| Case | Practical choice |
|---|---|
| Unknown-length HTTP/1.1 body | Use the library’s streaming support |
| Known-length HTTP/1.1 body | Usually Content-Length |
| HTTP/2 connection | Do not set chunked or Transfer-Encoding |
| Missing terminal zero chunk | Treat the body as incomplete |
Wire example
HTTP/1.1 200 OK
Transfer-Encoding: chunked
4
Wiki
5
pedia
0Sources
[RFC 9112 §§6.1, 6.2, 7.1](https://www.rfc-editor.org/rfc/rfc9112.html#section-7.1)
[RFC 9113 §8.2.2](https://www.rfc-editor.org/rfc/rfc9113.html#section-8.2.2)