spring-cloud/spring-cloud-gateway

Compute forwarded: header correctly when HTTP2 is enabled

Aberta

#3.106 aberto em 18 de out. de 2023

 (1 comentário) (0 reação) (0 responsável)Java (3.204 forks)batch import
enhancementhelp wanted

Métricas do repositório

Stars
 (4.284 estrelas)
Métricas de merge de PR
 (Mesclagem média 1d 21h) (18 fundiu PRs em 30d)

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.

Guia do colaborador