Skip to content

Support HTTP trailer fields #33640

Open
Open
@bclozel

Description

@bclozel

The HTTP protocol supports, in some situation, the addition of "trailer fields" after the entity body. They're often used for supplying information about message integrity, metrics, or post-processing information. While this information could be in theory sent with regular HTTP headers, it is sometimes needed to send/receive the entity body first. For example, buffering the entire body for calculating message integrity would require too much memory, or we need to write the body first before sending out telemetry.

This issue is about supporting HTTP trailer fields in Spring Framework, meaning considering those in:

  • the base org.springframework.http infrastructure
  • the Spring MVC annotation and functional programming models
  • the Spring WebFlux annotation and functional programming models
  • all our clients: WebClient, RestClient, RestTemplate
  • our testing support (MockMvc, etc)

We'll treat this as an umbrella issue for the points listed above.

There are several key aspects that we should pay attention to while designing the API and implementing support.

Constraints

A trailer section is only possible when supported by the version of HTTP in use and enabled by an explicit framing mechanism. For example, the chunked transfer coding in HTTP/1.1 allows a trailer section to be sent after the content

This means that setting a "Content-Length" response header is incompatible with trailer fields.

Also, the client should send a TE: trailers HTTP request header if it is willing to accept trailers in the respnose. The server must set the "Trailer" header with the list of trailer fields to be sent.

Unlike HTTP headers, request/response trailers are only available at a certain point in the exchange lifecyle. The API must reflect this asynchronous nature to ensure that trailers are read/written at the right time.

We should consider how we can make this as easy and transparent as possible for developers.

Server: Servlet API support

See the request API for getting trailer fields and the response API for supplying them.

Server: Reactive support

Reactor Netty, Jetty and Undertow seem to support trailer fields on their native APIs.

HTTP clients

  • The JDK HttpClient does not support sending nor receiving trailer fields.
  • Apache HttpComponents client does not support sending nor receiving trailer fields.
  • Reactor Netty client supports receiving trailer fields, but not sending them.
  • the Jetty client supports both sending and receiving trailer fields.

Library support is still spotty, we cannot expose this feature on our HTTP clients at this time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions