files/en-us/web/http/reference/headers/transfer-encoding/index.md
The HTTP Transfer-Encoding {{glossary("request header", "request")}} and {{glossary("response header")}} specifies the form of encoding used to transfer messages between nodes on the network.
Transfer-Encoding is a hop-by-hop header, that is applied to a message between two nodes, not to a resource itself.
Each segment of a multi-node connection can use different Transfer-Encoding values.
If you want to compress data over the whole connection, use the end-to-end {{HTTPHeader("Content-Encoding")}} header instead.
In practice this header is rarely used, and in those cases it is almost always used with chunked.
That said, the specification indicates that when present in a message it indicates the compression used on the message in that hop, and/or whether the message has been chunked.
For example, Transfer-Encoding: gzip, chunked indicates that the content has been compressed using the gzip coding and then chunked using the chunked coding while forming the message body.
The header is optional in responses to a {{HTTPMethod("HEAD")}} request as these messages have no body and, therefore, no transfer encoding.
When present it indicates the value that would have applied to the corresponding response to a {{HTTPMethod("GET")}} message, if that GET request did not include a preferred Transfer-Encoding.
<table class="properties"> <tbody> <tr> <th scope="row">Header type</th> <td> {{Glossary("Request header")}}, {{Glossary("Response header")}}, {{Glossary("Content header")}} </td> </tr> <tr> <th scope="row">{{Glossary("Forbidden request header")}}</th> <td>Yes</td> </tr> </tbody> </table>[!WARNING] HTTP/2 disallows all uses of the
Transfer-Encodingheader. HTTP/2 and later provide more efficient mechanisms for data streaming than chunked transfer. Usage of the header in HTTP/2 may likely result in a specificprotocol error.
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
chunked
\r\n and then the chunk itself, followed by another \r\n.
The terminating chunk is a zero-length chunk.compress
deflate
gzip
x-gzip as an alias, for compatibility purposes.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
Welcome\r\n
1c\r\n
to Mozilla Developer Network\r\n
0\r\n
\r\n
{{Specifications}}
{{Compat}}