From a3e496a521550669b48a7d027b4098107f07c30f Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 1 May 2017 20:28:16 -0700 Subject: [PATCH] Not try to compresses HttpMessage if IDENTITY header value is set. Motivation: If Content-Encoding: IDENTITY is used we should not try to compress the http message but just let it pass-through. Modifications: Remove "!" Result: Fixes [#6689] --- .../codec/http/HttpContentCompressor.java | 3 +-- .../codec/http/HttpContentCompressorTest.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java index 134be08c00..11c6129333 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java @@ -101,8 +101,7 @@ public class HttpContentCompressor extends HttpContentEncoder { @Override protected Result beginEncode(HttpResponse headers, String acceptEncoding) throws Exception { String contentEncoding = headers.headers().get(HttpHeaderNames.CONTENT_ENCODING); - if (contentEncoding != null && - !HttpHeaderValues.IDENTITY.contentEqualsIgnoreCase(contentEncoding)) { + if (HttpHeaderValues.IDENTITY.contentEqualsIgnoreCase(contentEncoding)) { return null; } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java index 2235cb64c4..4946328eba 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java @@ -373,6 +373,28 @@ public class HttpContentCompressorTest { } } + @Test + public void testIdentity() throws Exception { + EmbeddedChannel ch = new EmbeddedChannel(new HttpContentCompressor()); + assertTrue(ch.writeInbound(newRequest())); + + FullHttpResponse res = new DefaultFullHttpResponse( + HttpVersion.HTTP_1_1, HttpResponseStatus.OK, + Unpooled.copiedBuffer("Hello, World", CharsetUtil.US_ASCII)); + int len = res.content().readableBytes(); + res.headers().set(HttpHeaderNames.CONTENT_LENGTH, len); + res.headers().set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.IDENTITY); + assertTrue(ch.writeOutbound(res)); + + FullHttpResponse response = (FullHttpResponse) ch.readOutbound(); + assertEquals(String.valueOf(len), response.headers().get(HttpHeaderNames.CONTENT_LENGTH)); + assertEquals(HttpHeaderValues.IDENTITY.toString(), response.headers().get(HttpHeaderNames.CONTENT_ENCODING)); + assertEquals("Hello, World", response.content().toString(CharsetUtil.US_ASCII)); + response.release(); + + assertTrue(ch.finishAndReleaseAll()); + } + private static FullHttpRequest newRequest() { FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"); req.headers().set(HttpHeaderNames.ACCEPT_ENCODING, "gzip");