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");