I have a spring-boot web application with embedded tomcat, running on port 28081, and httpd configured for proxying like this:
ProxyPass / http://localhost:28081/
ProxyPassReverse / http://localhost:28081/
Then in a jsp page I need to pass the full request URL to a silverlight widget;but
${pageContext.request.serverName}:${pageContext.request.serverPort}
will resolve to http://localhost:28081
.
So I thought to rely on X-Forwarded-Host
, but there are cases when it does contain more than one proxy address, separated by comma. I am not sure it is safe to trust the order of the addresses will be preserved.
Is there a better way to do this, be that in the jsp, in the httpd configuration or in the controller code?
In the controller you can use ServletUriComponentsBuilder
: initialize it from the request and it picks out the proxy headers and builds the URI for the origin for you, e.g. String uri = ServletUriComponentsBuilder.fromCurrentRequest().build().toString()
.