knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject knox git commit: KNOX-897 - X-Forwarded-Port incorrectly defaults to the one configured for Knox if standard ports (80 and 443) are used (Attila Kanto via Sandeep More)
Date Thu, 09 Mar 2017 16:57:22 GMT
Repository: knox
Updated Branches:
  refs/heads/master 6c0000974 -> 3ee68053e


KNOX-897 - X-Forwarded-Port incorrectly defaults to the one configured for Knox if standard
ports (80 and 443) are used (Attila Kanto via Sandeep More)


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/3ee68053
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/3ee68053
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/3ee68053

Branch: refs/heads/master
Commit: 3ee68053e7d41d3aa6e8777e5e599596fc7ce6a1
Parents: 6c00009
Author: Sandeep More <more@apache.org>
Authored: Thu Mar 9 11:56:45 2017 -0500
Committer: Sandeep More <more@apache.org>
Committed: Thu Mar 9 11:56:45 2017 -0500

----------------------------------------------------------------------
 .../filter/rewrite/impl/UrlRewriteResponse.java       | 14 ++++++++++----
 .../filter/XForwardedHeaderRequestWrapper.java        |  9 ++++++++-
 2 files changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/3ee68053/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
index 2933cfb..c006d01 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
@@ -240,7 +240,11 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements
Params
 
   private String getGatewayParam( String name ) {
     if( "url".equals( name ) ) {
-      return xForwardedScheme + "://" + xForwardedHostname + ":" + xForwardedPort + request.getContextPath();
+      if( xForwardedPort == null ) {
+        return xForwardedScheme + "://" + xForwardedHostname + request.getContextPath();
+      } else {
+        return xForwardedScheme + "://" + xForwardedHostname + ":" + xForwardedPort + request.getContextPath();
+      }
     } else if( "scheme".equals( name ) ) {
       return xForwardedScheme;
     } else if( "host".equals( name ) ) {
@@ -248,7 +252,11 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements
Params
     } else if( "port".equals( name ) ) {
         return xForwardedPort;
     } else if( "addr".equals( name ) || "address".equals( name ) ) {
-      return xForwardedHostname + ":" + xForwardedPort;
+      if( xForwardedPort == null ) {
+        return xForwardedHostname;
+      } else {
+        return xForwardedHostname + ":" + xForwardedPort;
+      }
     } else if( "path".equals( name ) ) {
       return request.getContextPath();
     } else {
@@ -315,8 +323,6 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements
Params
       }
     } else {
       xForwardedHostname = getRequestLocalHostName();
-    }
-    if (xForwardedPort == null) {
       xForwardedPort = Integer.toString( request.getLocalPort() );
     }
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/3ee68053/gateway-server-xforwarded-filter/src/main/java/org/apache/hadoop/gateway/filter/XForwardedHeaderRequestWrapper.java
----------------------------------------------------------------------
diff --git a/gateway-server-xforwarded-filter/src/main/java/org/apache/hadoop/gateway/filter/XForwardedHeaderRequestWrapper.java
b/gateway-server-xforwarded-filter/src/main/java/org/apache/hadoop/gateway/filter/XForwardedHeaderRequestWrapper.java
index 787ed52..07dc943 100644
--- a/gateway-server-xforwarded-filter/src/main/java/org/apache/hadoop/gateway/filter/XForwardedHeaderRequestWrapper.java
+++ b/gateway-server-xforwarded-filter/src/main/java/org/apache/hadoop/gateway/filter/XForwardedHeaderRequestWrapper.java
@@ -118,7 +118,14 @@ public class XForwardedHeaderRequestWrapper extends GatewayRequestWrapper
{
   private static String getForwardedPort( HttpServletRequest request ) {
     String value = request.getHeader( X_FORWARDED_PORT );
     if( value == null ) {
-      value = Integer.toString( request.getLocalPort() );
+      String forwardedHost = getForwardedHost( request );
+      int separator = forwardedHost.indexOf( ":" );
+      if ( separator > 0 ) {
+          value = forwardedHost.substring(separator + 1, forwardedHost.length());
+      } else {
+          // use default ports
+          value = request.isSecure() ? "443" : "80";
+      }
     }
     return value;
   }


Mime
View raw message