← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6169: Added support for X-Forwarded-Proto and X-Forwarded-Port, this will help link generation when beh...

 

------------------------------------------------------------
revno: 6169
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-03-05 10:03:35 +0100
message:
  Added support for X-Forwarded-Proto and X-Forwarded-Port, this will help link generation when behind a reverse proxy. These headers will need to be set either static or dynamic on the proxy side. It will fallback to using normal HttpServletRequest getPort/getScheme if they are not present. This is necessary when you're proxy is on SSL and your DHIS instance is not.
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java	2011-12-22 18:14:45 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java	2012-03-05 09:03:35 +0000
@@ -1121,10 +1121,31 @@
     public static String createRootPath( HttpServletRequest request )
     {
         StringBuilder builder = new StringBuilder();
-        builder.append( request.getScheme() );
+        String xForwardedProto = request.getHeader( "X-Forwarded-Proto" );
+        String xForwardedPort = request.getHeader( "X-Forwarded-Port" );
+
+        if ( xForwardedProto != null && (xForwardedProto.equalsIgnoreCase( "http" ) || xForwardedProto.equalsIgnoreCase( "https" )) )
+        {
+            builder.append( xForwardedProto );
+        }
+        else
+        {
+            builder.append( request.getScheme() );
+        }
+
 
         builder.append( "://" ).append( request.getServerName() );
 
+        int port;
+
+        try
+        {
+            port = Integer.parseInt( xForwardedPort );
+        } catch ( NumberFormatException e )
+        {
+            port = request.getServerPort();
+        }
+
         if ( request.getServerPort() != 80 && request.getServerPort() != 443 )
         {
             builder.append( ":" ).append( request.getServerPort() );