Compute forwarded: header correctly when HTTP2 is enabled
#3106 opened on Oct 18, 2023
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:
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.