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);
|
assertEncodedResponse(ch);
|
||||||
|
|
||||||
ch.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT);
|
ch.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT);
|
||||||
HttpContent chunk = ch.readOutbound();
|
HttpContent chunk = (HttpContent) ch.readOutbound();
|
||||||
assertThat(ByteBufUtil.hexDump(chunk.content()), is("1f8b0800000000000000"));
|
assertThat(ByteBufUtil.hexDump(chunk.content()), is("1f8b080000000000000003000000000000000000"));
|
||||||
chunk.release();
|
|
||||||
|
|
||||||
chunk = ch.readOutbound();
|
|
||||||
assertThat(ByteBufUtil.hexDump(chunk.content()), is("03000000000000000000"));
|
|
||||||
assertThat(chunk, is(instanceOf(HttpContent.class)));
|
assertThat(chunk, is(instanceOf(HttpContent.class)));
|
||||||
chunk.release();
|
chunk.release();
|
||||||
|
|
||||||
|
@ -279,12 +279,17 @@ public class JZlibEncoder extends ZlibEncoder {
|
|||||||
@Override
|
@Override
|
||||||
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
|
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
|
||||||
if (finished) {
|
if (finished) {
|
||||||
|
out.writeBytes(in);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int inputLength = in.readableBytes();
|
||||||
|
if (inputLength == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Configure input.
|
// Configure input.
|
||||||
int inputLength = in.readableBytes();
|
|
||||||
boolean inHasArray = in.hasArray();
|
boolean inHasArray = in.hasArray();
|
||||||
z.avail_in = inputLength;
|
z.avail_in = inputLength;
|
||||||
if (inHasArray) {
|
if (inHasArray) {
|
||||||
|
@ -195,6 +195,10 @@ public class JdkZlibEncoder extends ZlibEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int len = uncompressed.readableBytes();
|
int len = uncompressed.readableBytes();
|
||||||
|
if (len == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int offset;
|
int offset;
|
||||||
byte[] inAry;
|
byte[] inAry;
|
||||||
if (uncompressed.hasArray()) {
|
if (uncompressed.hasArray()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user