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 56d98fe945..67e29007a1 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 @@ -227,12 +227,8 @@ public class HttpContentCompressorTest { assertEncodedResponse(ch); ch.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT); - HttpContent chunk = ch.readOutbound(); - assertThat(ByteBufUtil.hexDump(chunk.content()), is("1f8b0800000000000000")); - chunk.release(); - - chunk = ch.readOutbound(); - assertThat(ByteBufUtil.hexDump(chunk.content()), is("03000000000000000000")); + HttpContent chunk = (HttpContent) ch.readOutbound(); + assertThat(ByteBufUtil.hexDump(chunk.content()), is("1f8b080000000000000003000000000000000000")); assertThat(chunk, is(instanceOf(HttpContent.class))); chunk.release(); diff --git a/codec/src/main/java/io/netty/handler/codec/compression/JZlibEncoder.java b/codec/src/main/java/io/netty/handler/codec/compression/JZlibEncoder.java index c95fb406ea..3868bfb868 100644 --- a/codec/src/main/java/io/netty/handler/codec/compression/JZlibEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/compression/JZlibEncoder.java @@ -279,12 +279,17 @@ public class JZlibEncoder extends ZlibEncoder { @Override protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception { if (finished) { + out.writeBytes(in); + return; + } + + int inputLength = in.readableBytes(); + if (inputLength == 0) { return; } try { // Configure input. - int inputLength = in.readableBytes(); boolean inHasArray = in.hasArray(); z.avail_in = inputLength; if (inHasArray) { diff --git a/codec/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java b/codec/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java index 6b77061608..49be347890 100644 --- a/codec/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java @@ -195,6 +195,10 @@ public class JdkZlibEncoder extends ZlibEncoder { } int len = uncompressed.readableBytes(); + if (len == 0) { + return; + } + int offset; byte[] inAry; if (uncompressed.hasArray()) {