HTTP header Transfer-Encoding
The Transfer-Encoding header specifies the form of encoding used to safely transfer the payload body to the user.
Syntax
Transfer-Encoding: chunked
Transfer-Encoding: compress
Transfer-Encoding: deflate
Transfer-Encoding: gzip
// Several values can be listed, separated by a comma
Transfer-Encoding: gzip, chunked
Directives
chunked
Data is sent in a series of chunks. The
Content-Length header is omitted in this case and
at the beginning of each chunk you need to add the
length of the current chunk in hexadecimal format,
followed by ‘\r\n’ and then the chunk itself,
followed by another ‘\r\n’. The terminating chunk
is a regular chunk, with the exception that its
length is zero. It is followed by the trailer,
which consists of a (possibly empty) sequence of
header fields.
compress
deflate
gzip
Examples
Chunked encoding
Chunked encoding is useful when larger amounts of data are sent to the client and the total size of the response may not be known until the request has been fully processed. For example, when generating a large HTML table resulting from a database query or when transmitting large images.
A chunked response looks like this:
HTTP/1.1 200 OK
Content-Type: text/plain
Transfer-Encoding: chunked
7\r\n
Mozilla\r\n
11\r\n
Developer Network\r\n
0\r\n
\r\n