Trailer
HTTP message bodies sent with the "chunked" transfer coding may include additional HTTP headers, this header lists any headers expected to be included in the trailer section, but whose value will not be known until the trailer is written out.
Use of trailers is limited to specialized applications, where this header can optimize applications such as message digests, or other metadata that is computed against the message body.
These headers are currently known to include the Server-Timing
header, and the (now obsolete) Content-MD5
header.
Writing requests (clients)
The Trailer
header is rarely used by user agents, but valid.
If the request contains a body transferred with the "chunked" transfer encoding, and it contains trailers, the client should include a Trailer
header listing the headers that the client will include in the trailer section of the chunked body.
Reading requests (servers)
The Trailer header is designed to give the server advance notice that more headers will appear, so if the server wishes to perform computations over the message body that it otherwise wouldn't need to, it can know to do so.
This header can typically be ignored, unless the application implements trailers for some purpose; see the relevant headers for details.
Writing responses (servers)
Servers may wish to include trailers such as content digests or timing information, that's related to the message body, but without buffering the entire message in memory. If the client has sent a TE header with a "trailers" value, the server can send a chunked response with trailers. List the trailers being prepared in a Trailer
header, then write the final trailers at the end of the chunked encoding.
Reading responses (clients)
Clients that support trailers and wish to receive them should send the TE header with a "trailers" value.
Overview table
- Name
- Trailer
- Description
- Lists headers expected in the chunked encoding's trailer section.
- Direction
- Both
- Specification
- RFC 7230: HTTP/1.1 Message Syntax and Routing §4.4. Trailer
Syntax
Trailer = 1#field-name
Example
An example of a complete HTTP response with a chunked three-byte body (a period with CRLF line ending) and a Server-Timing
trailer. The CR-LF line endings are shown explicitly for visual reasons.
- First, there is the HTTP response headers
- A blank line terminates the HTTP headers
- The remainder of the document is the chunked body, the first line specifies how many bytes to read (in base 16)
- Three bytes are read, including a CRLF line ending (which is considered part of the document), then a CRLF to end the chunk
- Another chunk-length line is read; the value of zero indicates it is the last chunk. No bytes are read, and another CRLF is read to end the final chunk.
- Any number of headers are read the similar to HTTP headers, one per line until a blank line is encountered, which signals the end of the of the entire chunked message body.
HTTP/1.1 200 OK␍␊
Content-Type: text/plain␍␊
Transfer-Encoding: chunked␍␊
Trailer: Server-Timing␍␊
␍␊
3␍␊
.␍␊
␍␊
0␍␊
␍␊
Server-Timing: total;dur=110.2␍␊
␍␊