-
Notifications
You must be signed in to change notification settings - Fork 471
ControllerLinkBuilder should be extensible #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
In terms of enhancing the behavior of ServletUriComponentsBuilder:
I agree that filing a ticket in SPR JIRA is appropriate. |
Thanks. I have just opened an issue on Spring JIRA. |
When setting up the builder we now set the host to the value held in the X-Forwarded-Host [0] header if present. This allows to render appropriate URIs in reverse proxy scenarios. This is essentially an extension of ServletUriComponentsBuilder that will be fixed in there eventually. See SPR-10110 [1] for details. [0] http://tools.ietf.org/html/draft-ietf-appsawg-http-forwarded-10 [1] https://jira.springsource.org/browse/SPR-10110
Added a temporary fix to |
…st header. When setting up the builder we now set the host to the value held in the X-Forwarded-Host [0] header if present. This allows to render appropriate URIs in reverse proxy scenarios. This is essentially an extension of ServletUriComponentsBuilder that will be fixed in there eventually. See SPR-10110 [1] for details. [0] http://tools.ietf.org/html/draft-ietf-appsawg-http-forwarded-10 [1] https://jira.springsource.org/browse/SPR-10110
Current implementation of
ControllerLinkBuilder
relies on Spring'sServletUriComponentsBuilder
to construct links. The problem withServletUriComponentsBuilder
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 Spring's
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
ControllerLinkBuilder
logic to not use Spring'sServletUriComponentsBuilder
.The text was updated successfully, but these errors were encountered: