HTTP Content Encoder allow EmptyLastHttpContent
Related: #3107, origianlly written by @Scottmitch Motiviation: The HttpContentEncoder does not account for an EmptyLastHttpContent being provides 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 trnasfer 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
3451bce17f
commit
4772989ddd
@ -183,12 +183,18 @@ public class JdkZlibEncoder extends OneToOneStrictEncoder implements LifeCycleAw
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChannelBuffer uncompressed = (ChannelBuffer) msg;
|
final ChannelBuffer uncompressed = (ChannelBuffer) msg;
|
||||||
byte[] in = new byte[uncompressed.readableBytes()];
|
final int uncompressedLen = uncompressed.readableBytes();
|
||||||
|
if (uncompressedLen == 0) {
|
||||||
|
return uncompressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
final byte[] in = new byte[uncompressedLen];
|
||||||
uncompressed.readBytes(in);
|
uncompressed.readBytes(in);
|
||||||
|
|
||||||
int sizeEstimate = estimateCompressedSize(in.length);
|
final int sizeEstimate = estimateCompressedSize(uncompressedLen);
|
||||||
ChannelBuffer compressed = ChannelBuffers.dynamicBuffer(sizeEstimate, channel.getConfig().getBufferFactory());
|
final ChannelBuffer compressed =
|
||||||
|
ChannelBuffers.dynamicBuffer(sizeEstimate, channel.getConfig().getBufferFactory());
|
||||||
|
|
||||||
synchronized (deflater) {
|
synchronized (deflater) {
|
||||||
if (isGzip()) {
|
if (isGzip()) {
|
||||||
|
@ -266,25 +266,30 @@ public class ZlibEncoder extends OneToOneStrictEncoder implements LifeCycleAware
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChannelBuffer result;
|
final ChannelBuffer result;
|
||||||
synchronized (z) {
|
synchronized (z) {
|
||||||
try {
|
try {
|
||||||
// Configure input.
|
// Configure input.
|
||||||
ChannelBuffer uncompressed = (ChannelBuffer) msg;
|
final ChannelBuffer uncompressed = (ChannelBuffer) msg;
|
||||||
byte[] in = new byte[uncompressed.readableBytes()];
|
final int uncompressedLen = uncompressed.readableBytes();
|
||||||
|
if (uncompressedLen == 0) {
|
||||||
|
return uncompressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
final byte[] in = new byte[uncompressedLen];
|
||||||
uncompressed.readBytes(in);
|
uncompressed.readBytes(in);
|
||||||
z.next_in = in;
|
z.next_in = in;
|
||||||
z.next_in_index = 0;
|
z.next_in_index = 0;
|
||||||
z.avail_in = in.length;
|
z.avail_in = uncompressedLen;
|
||||||
|
|
||||||
// Configure output.
|
// Configure output.
|
||||||
byte[] out = new byte[(int) Math.ceil(in.length * 1.001) + 12 + wrapperOverhead];
|
final byte[] out = new byte[(int) Math.ceil(uncompressedLen * 1.001) + 12 + wrapperOverhead];
|
||||||
z.next_out = out;
|
z.next_out = out;
|
||||||
z.next_out_index = 0;
|
z.next_out_index = 0;
|
||||||
z.avail_out = out.length;
|
z.avail_out = out.length;
|
||||||
|
|
||||||
// Note that Z_PARTIAL_FLUSH has been deprecated.
|
// Note that Z_PARTIAL_FLUSH has been deprecated.
|
||||||
int resultCode = z.deflate(JZlib.Z_SYNC_FLUSH);
|
final int resultCode = z.deflate(JZlib.Z_SYNC_FLUSH);
|
||||||
if (resultCode != JZlib.Z_OK) {
|
if (resultCode != JZlib.Z_OK) {
|
||||||
ZlibUtil.fail(z, "compression failure", resultCode);
|
ZlibUtil.fail(z, "compression failure", resultCode);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user