Add support for X-Forwarded-Host in ServletUriComponentsBuilder [SPR-10110] #14743
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: enhancement
A general enhancement
Milestone
Adarsh Ramamurthy opened SPR-10110 and commented
The problem with
ServletUriComponentsBuilder
is that it is poorly designed (uses only static method calls), eliminating the possibility to extend and enhance the behaviour.One typical scenario that I discovered yesterday:
Our tomcat server is hosted behind Apache. The client (browser) accesses a URL using
www.example.com/path/to/resource
. However, because of the way Apache has been set up, it doesn't send along theHost
header value ofwww.example.com
to Tomcat. Instead, it sends the internal IP address. The original hostname ofwww.example.com
is set in anX-Forwarded-Host
header.Now, because
ServletUriComponentsBuilder
usesrequest.getServerName()
to construct the hostname part of the URL, any generated URLs will have the internal IP address instead ofwww.example.com
.The only way I can fix this currently is by either:
HttpServletRequestWrapper
that takes the value ofX-Forwarded-Host
header and sets it toHost
header.OR
ServletUriComponentsBuilder
logic.Reference URL: spring-projects/spring-hateoas#33
Issue Links:
Referenced from: commits 153508a
The text was updated successfully, but these errors were encountered: