type=page
status=published
title=HTTP Trailer
next=servlets015.html
prev=servlets014a.html
~~~~~~
= HTTP Trailer


[[http-trailer]]
HTTP Trailer
------------

HTTP trailer is a collection of a special type of HTTP headers that comes
after the response body. The trailer response header allows the sender to
include additional fields at the end of chunked messages in order to supply
metadata that might be dynamically generated while the message body is sent,
such as a message integrity check, digital signature, or post-processing status.

If trailer headers are ready for reading, `isTrailerFieldsReady()` will return
`true`. Then a servlet can read trailer headers of the HTTP request using the
 `getTrailerFields` method of the `HttpServletRequest` interface. If trailer
 headers are not ready for reading, `isTrailerFieldsReady()` returns `false`
 and will cause an `IllegalStateException`.

A servlet can write trailer headers to the response by providing a supplier to
the `setTrailerFields()` method of the `HttpServletResponse` interface. The
following headers and types of headers must _not_ be included in the set of
keys in the map passed to `setTrailerFields()`: `Transfer-Encoding`,
`Content-Length`, `Host`, controls and conditional headers, authentication
headers, `Content-Encoding`, `Content-Type`, `Content-Range`, and `Trailer`.
When sending response trailers, you must include a regular header, called `Trailer`,
whose value is a comma-separated list of all the keys in the map that is supplied
to the `setTrailerFields()` method. The value of the `Trailer` header lets the
client know what trailers to expect.

The supplier of the trailer headers can be obtained by accessing the
`getTrailerFields()` method of the `HttpServletResponse` interface.


See the https://javaee.github.io/javaee-spec/[javadoc] for `getTrailerFields()`
and `isTrailerFieldsReady()` in `HttpServletRequest`, and `getTrailerFields()`
and `setTrailerFields()` in `HttpServletResponse`.
