Object msg = e.getMessage();
if (msg instanceof HttpResponse && ((HttpResponse) msg).getStatus().getCode() == 100) {
// 100-continue response must be passed through.
ctx.sendDownstream(e);
} else if (msg instanceof HttpMessage) {
HttpMessage m = (HttpMessage) msg;
encoder = null;
// Determine the content encoding.
String acceptEncoding = acceptEncodingQueue.poll();
if (acceptEncoding == null) {
acceptEncoding = this.previousEncoding;
} else {
this.previousEncoding = acceptEncoding;
}
if ((encoder = newContentEncoder(acceptEncoding)) != null) {
// Encode the content and remove or replace the existing headers
// so that the message looks like a decoded message.
m.setHeader(
HttpHeaders.Names.CONTENT_ENCODING,
getTargetContentEncoding(acceptEncoding));
if (!m.isChunked()) {
ChannelBuffer content = m.getContent();
// Encode the content.
content = ChannelBuffers.wrappedBuffer(
encode(content), finishEncode());
// Replace the content.
m.setContent(content);
// if (m.containsHeader(HttpHeaders.Names.CONTENT_LENGTH)) {
// m.setHeader(
// HttpHeaders.Names.CONTENT_LENGTH,
// Integer.toString(content.readableBytes()));
// }
}
}
//ALWAYS SET THE Content_LEngth
m.setHeader(
HttpHeaders.Names.CONTENT_LENGTH,
Integer.toString(m.getContent().readableBytes()));
// Because HttpMessage is a mutable object, we can simply forward the write request.
ctx.sendDownstream(e);
} else if (msg instanceof HttpChunk) {
HttpChunk c = (HttpChunk) msg;
ChannelBuffer content = c.getContent();