Transfer-Encoding is primarily intended to accurately delimit and safely transfer a dynamically generated payload.
The mostly used Transfer-Encoding method is chunked transfer encoding. For example, servers may use chunked encoding when they need to send a large amount of data, or the total length of the data is unknown.
When chunked transfer encoding is used, the data stream is divided into a series of non-overlapping chunks. Each chunk is sent and received independently of each other and is preceded by its own size in bytes.
No knowledge of the data stream outside the currently-being-processed chunk is required by either the sender or the receiver at any given time. Transmission ends when a zero-length chunk is received.
Transfer-Encoding Directives
- chunked: data is sent in series of non-overlapping chunks.
- gzip: GNU zip format uses the deflate algorithm for compression.
- deflate: compression based on the deflate algorithm.
- compress: UNIX "compress" program method, deprecated and replaced by gzip or deflate
Many older HTTP/1.0 applications do not support the Transfer-Encoding header. Also, the Transfer-Encoding header must not be used with HTTP/2.