Transfer-Encoding
The Transfer-Encoding header field lists the mechanisms used by the connection to transmit the message body (including the content coding already applied to it). The primary use is to signal a chunked transmission of the message body when the length is not known in advance.
Transfer-Encoding is a property of an HTTP/1.1 connection (it is not used in HTTP/1.0 and, HTTP/2 has an entirely different mechanism for transferring payloads).
It is mutually exclusive with the Content-Length header. See RFC 7230 §3.3.3. Message Body Length for how to determine the message body length.
Messages can be encoded with any number of transfer codings, but if any, messages must use chunked
as the outermost one, so that the end of the transfer can reliably be identified. Implementations will typically use "chunked" by itself, and any compression is applied as a content coding using the Content-Encoding header.
Writing requests (clients)
Transfer-Encoding is typically sent in HTTP/1.1 requests when the length of the upload is unknown. Servers may require the client send a Content-Length header instead, and will return 411 Length Required
error in this case.
Reading requests (servers)
This header is only meaningful in HTTP/1.1 connections, return 400 Client Error
and close the connection if used in another HTTP version.
Parse the headers outermost to innermost. If any tokens are not understood, return 501 (Not Implemented)
with a short description.
The outermost transfer coding can define when an EOF is present
Writing responses (servers)
Transfer-Encoding is frequently used for responses where the full length of the message is not known in advance of writing the response body.
A server MUST NOT send a Transfer-Encoding header field in any response with a status code of 1xx (Informational) or 204 (No Content), or in response to a CONNECT request; as these responses do not have a body.
Reading responses (clients)
It is difficult to recover from a response with an unknown Transfer-Encoding header. See RFC 7230 §3.3.3. Message Body Length for advice on how to read responses with a Transfer-Encoding header.
Overview table
- Name
- Transfer-Encoding
- Description
- Lists transfer encodings used to transmit the message body.
- Direction
- Both
- Negotiated by
- TE
- Specification
- RFC 7230: HTTP/1.1: Message Syntax and Routing §3.3.1. Transfer-Encoding
Syntax
Transfer-Encoding = 1#transfer-coding
Example
Transfer-Encoding: gzip, chunked