Trailer
The HTTP Trailer header lists the header fields the sender will include in the trailer section of a chunked message.
Usage
The Trailer header announces which header fields appear after the final chunk in a chunked Transfer-Encoding message. Trailer fields carry metadata the sender cannot determine until the entire body has been transmitted, such as message integrity checksums, digital signatures, or post-processing status indicators.
A sender includes the Trailer header in the
message head to give the recipient advance notice of
which fields to expect. The recipient needs to have
signaled support for trailers by sending
TE: trailers in the request.
Trailer fields are useful in Streaming scenarios where the server generates the response body incrementally. A checksum over the entire body, for example, is only available after the last byte has been written.
Restrictions
Several categories of header fields are prohibited from appearing as trailers:
- Message framing headers such as Transfer-Encoding and Content-Length
- Routing headers such as Host
- Authentication headers such as Authorization and Set-Cookie
- Request modifier headers such as Max-Forwards
- Response controls such as Cache-Control
- Content format headers such as Content-Encoding, Content-Type, Content-Range, and Trailer itself
These restrictions exist because intermediaries and clients need these headers before processing the body.
Example
A server sends a chunked response with a trailer
field. The Trailer header in the message head
announces the Server-Timing field will follow the
body, carrying timing metrics computed after the
full response has been generated.
HTTP/1.1 200 OK
Content-Type: text/plain
Transfer-Encoding: chunked
Trailer: Server-Timing
7\r\n
Mozilla\r\n
9\r\n
Developer\r\n
0\r\n
Server-Timing: total;dur=135.7\r\n
\r\n
Multiple trailer fields are listed as a comma-separated value. This response announces both a timing field and a digest field in the trailer section.
Trailer: Server-Timing, Content-Digest
Takeaway
The Trailer header declares which fields the sender appends after the final chunk in a chunked transfer, enabling delivery of metadata like checksums and signatures computed over the complete message body.