You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by kr...@apache.org on 2018/10/22 13:42:09 UTC
knox git commit: KNOX-1534 - Avoid try/catch checking for gzip stream
Repository: knox
Updated Branches:
refs/heads/master 84d794f84 -> 87d7291bd
KNOX-1534 - Avoid try/catch checking for gzip stream
Signed-off-by: Kevin Risden <kr...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/87d7291b
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/87d7291b
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/87d7291b
Branch: refs/heads/master
Commit: 87d7291bd3bdfe498d6f692430b3d02fe47c21ab
Parents: 84d794f
Author: Kevin Risden <kr...@apache.org>
Authored: Fri Oct 19 12:05:35 2018 -0400
Committer: Kevin Risden <kr...@apache.org>
Committed: Mon Oct 22 09:41:25 2018 -0400
----------------------------------------------------------------------
.../filter/rewrite/impl/UrlRewriteResponse.java | 25 +++++++++++---------
1 file changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/87d7291b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteResponse.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteResponse.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteResponse.java
index ce16a9a..8d8f401 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteResponse.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteResponse.java
@@ -153,21 +153,18 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements Params
InputStream inStream;
OutputStream outStream;
- boolean isGzip = false;
+ // Use this way to check whether the input stream is gzip compressed, in case
+ // the content encoding header is unknown, as it could be unset in inbound response
+ boolean isGzip = false;
BufferedInputStream inBuffer = new BufferedInputStream(input, STREAM_BUFFER_SIZE);
-
- try {
- // Use this way to check whether the input stream is gzip compressed, in case
- // the content encoding header is unknown, as it could be unset in inbound response
- inBuffer.mark(STREAM_BUFFER_SIZE);
- inStream = new GZIPInputStream(new GZIPInputStreamHelperInputStream(inBuffer), STREAM_BUFFER_SIZE);
+ inBuffer.mark(2);
+ byte [] signature = new byte[2];
+ int len = inBuffer.read( signature ); //read the signature
+ if( len == 2 && signature[ 0 ] == (byte) 0x1f && signature[ 1 ] == (byte) 0x8b ) {
isGzip = true;
- } catch (IOException e) {
- // Not proper gzip content
- inBuffer.reset();
- inStream = inBuffer;
}
+ inBuffer.reset();
MimeType mimeType = getMimeType();
UrlRewriteFilterContentDescriptor filterContentConfig =
@@ -179,6 +176,12 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements Params
}
}
+ if(isGzip) {
+ inStream = new GZIPInputStream(new GZIPInputStreamHelperInputStream(inBuffer), STREAM_BUFFER_SIZE);
+ } else {
+ inStream = inBuffer;
+ }
+
InputStream filteredInput = UrlRewriteStreamFilterFactory.create(mimeType,
null,
inStream,