[MRM-834] use Apache 2.0 mod_proxy header if available for those that don't want to use ProxyPreserveHost

Merged from: r694564 on trunk


git-svn-id: https://svn.apache.org/repos/asf/archiva/branches@694565 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2008-09-12 00:34:57 +00:00
parent f2853ab049
commit c55236937b

View File

@ -80,15 +80,7 @@ public static String getBaseURL( HttpServletRequest request, String resource )
StringBuffer baseUrl = new StringBuffer();
baseUrl.append( request.getScheme() ).append( "://" );
baseUrl.append( request.getServerName() );
int portnum = request.getServerPort();
// Only add port if non-standard.
Integer defaultPortnum = (Integer) defaultSchemePortMap.get( request.getScheme() );
if ( ( defaultPortnum == null ) || ( defaultPortnum.intValue() != portnum ) )
{
baseUrl.append( ":" ).append( String.valueOf( portnum ) );
}
baseUrl.append( getServerName( request ) );
baseUrl.append( request.getContextPath() );
if ( StringUtils.isNotBlank( resource ) )
@ -103,4 +95,23 @@ public static String getBaseURL( HttpServletRequest request, String resource )
return baseUrl.toString();
}
private static String getServerName( HttpServletRequest request )
{
String name = request.getHeader( "X-Forwarded-Host" );
if ( name == null )
{
name = request.getServerName();
int portnum = request.getServerPort();
// Only add port if non-standard.
Integer defaultPortnum = (Integer) defaultSchemePortMap.get( request.getScheme() );
if ( ( defaultPortnum == null ) || ( defaultPortnum.intValue() != portnum ) )
{
name = name + ":" + String.valueOf( portnum );
}
return name;
}
return name;
}
}