HTTP Trailer Introduction
HTTP trailer is a collection of special kind of HTTP headers that comes after the response body.
Trailer is specified in RFC 7230. They are useful in the context of chunked transfer encoding and also in
the implementation of additional communication protocols. Servlet containers provide support for trailers.
If trailer headers are ready for reading, isTrailerFieldsReady()
will return true.
Then a servlet can read trailer headers of the HTTP request via the getTrailerFields()
method of the HttpServletRequest interface.
A servlet can write trailer headers to the response by providing a Supplier
to the setTrailerFields
method of the HttpServletResponse
interface. The Supplier
of the trailer headers
can be obtained by accessing the getTrailerFields()
method of the HttpServletResponse
interface.
Description of the Example
This is a simple Servlet application that demonstrate the usage of HTTP trailer API. This sample demonstrates
the following key features:
- Consuming a HTTP trailer from a HTTP request.
- Producing a HTTP trailer for a HTTP response.
Use This Example
Consume the request trailer and produce the response trailer