spring-cloud / spring-cloud/spring-cloud-gateway

Compute forwarded: header correctly when HTTP2 is enabled

Open
#3,106 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

Is your feature request related to a problem? Please describe.
It is possible to enable HTTP2 support in Spring Boot application like so:

server.http2.enabled=true

with this enabled and with embedded Tomcat running in HTTPS mode (at port 8443), the browsers (like Chrome) use the HTTP2 (shown as h2 in protocol column of Chrome devtools network panel), and due to the specs related to HTTP2 do not send the Host: localhost:8443 header. Instead the browsers send :authority: localhost:8443.

The code here:

https://github.com/spring-cloud/spring-cloud-gateway/blob/51367a8668c686e972f621874ec8e40ae21b56b2/spring-cloud-gateway-mvc/src/main/java/org/springframework/cloud/gateway/mvc/ProxyExchange.java#L418

relies on the Host: header and if not found uses the host and scheme from URI. The port is not set at all.

However there is code in Tomcat that does process the :authority: header and sets the values of req.getServerName() and req.getServerPort().

Describe the solution you'd like
The computation of forwarded: header should make use of values of req.getServerName() and req.getServerPort() because they are set from :authority: header, which is equivalent of Host: when HTTP2 is being used.

Describe alternatives you've considered
None.

Additional context
BTW libraries like HATEOAS rely on Host: header to return correct links in the response.

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

Start in spring-cloud-gateway-mvc/src/main/java/org/springframework/cloud/gateway/mvc/ProxyExchange.java around the forwarded-header computation linked in the issue. Check how HTTP/2 authority values reach req.getServerName() and req.getServerPort(), then verify that the forwarded header is correct for an HTTPS embedded Tomcat request using HTTP/2.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.