Repository: knox
Updated Branches:
  refs/heads/v0.9.0 7ca690cdb -> 667825e34


KNOX-754 scope change to just the Location header


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

Branch: refs/heads/v0.9.0
Commit: 667825e340067ce05a784832f0d1dffcd0132cb4
Parents: 7ca690c
Author: Sumit Gupta <su...@apache.org>
Authored: Mon Oct 17 12:03:15 2016 -0400
Committer: Sumit Gupta <su...@apache.org>
Committed: Mon Oct 17 12:21:22 2016 -0400

----------------------------------------------------------------------
 .../filter/rewrite/impl/UrlRewriteResponse.java  | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/667825e3/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 2c9c70d..182efda 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
@@ -112,12 +112,16 @@ public class UrlRewriteResponse extends 
GatewayResponseWrapper implements Params
     return IGNORE_HEADER_NAMES.contains( name );
   }
 
-  private String rewriteValue( String value, String rule ) {
+  private String rewriteValue(String value, String rule, boolean encode ) {
     try {
       Template input = Parser.parseLiteral( value );
       Template output = rewriter.rewrite( this, input, 
UrlRewriter.Direction.OUT, rule );
       if( output != null ) {
-        value = output.toEncodedString();
+        if (encode) {
+          value = output.toEncodedString();
+        } else {
+          value = output.getPattern();
+        }
       }
     } catch( URISyntaxException e ) {
       LOG.failedToParseValueForUrlRewrite( value );
@@ -129,7 +133,7 @@ public class UrlRewriteResponse extends 
GatewayResponseWrapper implements Params
   @Override
   public void setHeader( String name, String value ) {
     if( !ignoreHeader( name) ) {
-      value = rewriteValue( value, pickFirstRuleWithEqualsIgnoreCasePathMatch( 
headersFilterConfig, name ) );
+      value = rewriteValue( value, pickFirstRuleWithEqualsIgnoreCasePathMatch( 
headersFilterConfig, name ), needsEncoding(name) );
       super.setHeader( name, value );
     }
   }
@@ -139,11 +143,18 @@ public class UrlRewriteResponse extends 
GatewayResponseWrapper implements Params
   public void addHeader( String name, String value ) {
     if( !ignoreHeader( name ) ) {
       String rule = pickFirstRuleWithEqualsIgnoreCasePathMatch( 
headersFilterConfig, name );
-      value = rewriteValue( value, rule );
+      value = rewriteValue( value, rule, needsEncoding(name) );
       super.addHeader( name, value );
     }
   }
 
+  private boolean needsEncoding( String name ) {
+    if ( name.equalsIgnoreCase("Location") ) {
+      return true;
+    }
+    return false;
+  }
+
   @Override
   public OutputStream getRawOutputStream() throws IOException {
     return response.getOutputStream();

Reply via email to