HTTP Content Encoder allow EmptyLastHttpContent

Motiviation:
The HttpContentEncoder does not account for a EmptyLastHttpContent being provided as input.  This is useful in situations where the client is unable to determine if the current content chunk is the last content chunk (i.e. a proxy forwarding content when transfer encoding is chunked).

Modifications:
- HttpContentEncoder should not attempt to compress empty HttpContent objects

Result:
HttpContentEncoder supports a EmptyLastHttpContent to terminate the response.
This commit is contained in:
Scott Mitchell 2014-11-04 10:43:57 -05:00
parent e82595502b
commit 72a611a28f
3 changed files with 12 additions and 7 deletions

View File

@ -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();

View File

@ -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) {

View File

@ -195,6 +195,10 @@ public class JdkZlibEncoder extends ZlibEncoder {
}
int len = uncompressed.readableBytes();
if (len == 0) {
return;
}
int offset;
byte[] inAry;
if (uncompressed.hasArray()) {