*** Welcome to piglix ***

Chunked transfer encoding


Chunked transfer encoding is a data transfer mechanism in the (HTTP), version 1.1 and up. In chunked transfer encoding, the data are sent as a series of "chunks". The sender of chunked data must know the current chunk size but not the overall data size. Thus, dynamically generated content may be transmitted.

The chunked keyword in the Transfer-Encoding header is used to indicate chunked transfer. Each chunk is preceded by its size. The transmission ends when a zero-length chunk is encountered.

An early form of the chunked transfer encoding was proposed in 1994.

The introduction of chunked encoding provided various benefits:

For version 1.1 of the HTTP protocol, the chunked transfer mechanism is considered to be always and anyways acceptable, even if not listed in the TE (transfer encoding) request header field, and when used with other transfer mechanisms, should always be applied last to the transferred data and never more than one time. This transfer coding method also allows additional entity header fields to be sent after the last chunk if the client specified the "trailers" parameter as an argument of the TE field. The origin server of the response can also decide to send additional entity trailers even if the client did not specify the "trailers" option in the TE request field, but only if the metadata is optional (i.e. the client can use the received entity without them). Whenever the trailers are used, the server should list their names in the Trailer header field; 3 header field types are specifically prohibited from appearing as a trailer field: Transfer-Encoding, Content-Length and Trailer.

If a Transfer-Encoding field with a value of "chunked" is specified in an HTTP message (either a request sent by a client or the response from the server), the body of the message consists of an unspecified number of chunks, a terminating chunk, trailer, and a final CRLF sequence (i.e. carriage return followed by line feed).

Each chunk starts with the number of octets of the data it embeds expressed as a hexadecimal number in ASCII followed by optional parameters (chunk extension) and a terminating CRLF sequence, followed by the chunk data. The chunk is terminated by CRLF.


...
Wikipedia

...