twarne / xebia-france

Automatically exported from code.google.com/p/xebia-france
0 stars 0 forks source link

Missing support for 'X-Forwarded-Server' in XForwardedFilter #21

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The 'X-Forwarded-Server' header is used by Apache HTTPd's mod_proxy to capture 
the hostname of the proxy server. It is particularly useful to have this 
information available in the webapp, when a single instance of the web 
application serves more than one domain name (for example through the 
configuration of virtual host names).

The problem becomes visible when inspecting the value returned by 
javax.servlet.ServletRequest#getServerName(). At present, the XForwardedFilter 
implementation causes the hostname / ip address of the application server to 
show. The desired behavior would cause the hostname of the proxy to show.

Support for the 'X-Forworded-Server' request header is missing in versions up 
to and including version 1.0.8 of the xebia-servlet-extras library. Newer 
versions of the library are not available at this time (and are therefor 
untested).

A simplistic implementation of the desired feature id provided below. The 
following override can be added to the HttpServletRequestWrapper that is 
defined in the XForwardedFilter implementation.

@Override
public String getServerName() {
    String hostname = this.getHeader("X-Forwarded-Server");

    if (hostname != null) {
        return hostname;
    } else {
        return super.getServerName();
    }
}

Original issue reported on code.google.com by Guus.der...@gmail.com on 23 Sep 2013 at 8:18