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-1412 - Knox should honor the Content-Encoding header when it can
Date Mon, 06 Aug 2018 16:03:37 GMT
Repository: knox
Updated Branches:
  refs/heads/master 1d399f26a -> e51dc99ac


KNOX-1412 - Knox should honor the Content-Encoding header when it can


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

Branch: refs/heads/master
Commit: e51dc99ac30a183c66f113a400fc514b4be6ba9e
Parents: 1d399f2
Author: Sandeep More <more@apache.org>
Authored: Mon Aug 6 12:03:29 2018 -0400
Committer: Sandeep More <more@apache.org>
Committed: Mon Aug 6 12:03:29 2018 -0400

----------------------------------------------------------------------
 .../filter/rewrite/impl/UrlRewriteRequest.java      | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/e51dc99a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteRequest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteRequest.java
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteRequest.java
index 3a8ae65..f97b64f 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteRequest.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteRequest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.knox.gateway.filter.rewrite.impl;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.knox.gateway.filter.AbstractGatewayFilter;
 import org.apache.knox.gateway.filter.GatewayRequestWrapper;
 import org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
@@ -32,6 +33,7 @@ import org.apache.knox.gateway.util.MimeTypes;
 import org.apache.knox.gateway.util.urltemplate.Parser;
 import org.apache.knox.gateway.util.urltemplate.Resolver;
 import org.apache.knox.gateway.util.urltemplate.Template;
+import org.eclipse.jetty.http.HttpHeader;
 
 import javax.activation.MimeType;
 import javax.servlet.FilterConfig;
@@ -242,6 +244,20 @@ public class UrlRewriteRequest extends GatewayRequestWrapper implements
Resolver
     ServletInputStream input = super.getInputStream();
     if( getContentLength() != 0 ) {
       MimeType mimeType = getMimeType();
+
+      /* In cases where content type is application/text and content-encoding is gzip */
+      final String contentEncoding = getHeader(
+          HttpHeader.CONTENT_ENCODING.asString());
+      if (!StringUtils.isBlank(contentEncoding) && StringUtils
+          .containsAny(contentEncoding, "gzip", "compress", "deflate", "br")) {
+        /* This prevents adding filters based on content-type, which in most cases would
not be
+         * an issue but in cases where request specifies additional encoding this causes
issues
+         * see KNOX-1412
+         */
+        mimeType = MimeTypes
+            .create("application/" + contentEncoding, getCharacterEncoding());
+      }
+
       UrlRewriteFilterContentDescriptor filterContentConfig = getRewriteFilterConfig( bodyFilterName,
mimeType );
       if (filterContentConfig != null) {
         String asType = filterContentConfig.asType();


Mime
View raw message