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:
parent
e82595502b
commit
72a611a28f
@ -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();
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -195,6 +195,10 @@ public class JdkZlibEncoder extends ZlibEncoder {
|
||||
}
|
||||
|
||||
int len = uncompressed.readableBytes();
|
||||
if (len == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int offset;
|
||||
byte[] inAry;
|
||||
if (uncompressed.hasArray()) {
|
||||
|
Loading…
Reference in New Issue
Block a user