spring-projects / spring-projects/spring-framework

Support HTTP trailer fields

Open
#33,640 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

in: web type: enhancement
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

This is an umbrella issue spanning the org.springframework.http infrastructure, Spring MVC and WebFlux models, and testing support such as MockMvc. Start by reviewing the Servlet trailer APIs and the listed reactive-server capabilities; done requires a defined API and coordinated support across the selected layers, with tests for trailer timing and HTTP constraints.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.