Fix NETTY-432 HttpContentEncoder should not encode if Content-Encoding is set already and it is not 'identity'
This commit is contained in:
parent
a67cdaeb48
commit
e3386736c0
|
@ -96,38 +96,45 @@ public abstract class HttpContentEncoder extends SimpleChannelHandler {
|
||||||
|
|
||||||
encoder = null;
|
encoder = null;
|
||||||
|
|
||||||
// Determine the content encoding.
|
String contentEncoding = m.getHeader(HttpHeaders.Names.CONTENT_ENCODING);
|
||||||
String acceptEncoding = acceptEncodingQueue.poll();
|
if (contentEncoding != null &&
|
||||||
if (acceptEncoding == null) {
|
!HttpHeaders.Values.IDENTITY.equalsIgnoreCase(contentEncoding)) {
|
||||||
throw new IllegalStateException("cannot send more responses than requests");
|
// Content-Encoding is set already and it is not 'identity'.
|
||||||
}
|
ctx.sendDownstream(e);
|
||||||
|
} else {
|
||||||
|
// Determine the content encoding.
|
||||||
|
String acceptEncoding = acceptEncodingQueue.poll();
|
||||||
|
if (acceptEncoding == null) {
|
||||||
|
throw new IllegalStateException("cannot send more responses than requests");
|
||||||
|
}
|
||||||
|
|
||||||
boolean hasContent = m.isChunked() || m.getContent().readable();
|
boolean hasContent = m.isChunked() || m.getContent().readable();
|
||||||
if (hasContent && (encoder = newContentEncoder(acceptEncoding)) != null) {
|
if (hasContent && (encoder = newContentEncoder(acceptEncoding)) != null) {
|
||||||
// Encode the content and remove or replace the existing headers
|
// Encode the content and remove or replace the existing headers
|
||||||
// so that the message looks like a decoded message.
|
// so that the message looks like a decoded message.
|
||||||
m.setHeader(
|
m.setHeader(
|
||||||
HttpHeaders.Names.CONTENT_ENCODING,
|
HttpHeaders.Names.CONTENT_ENCODING,
|
||||||
getTargetContentEncoding(acceptEncoding));
|
getTargetContentEncoding(acceptEncoding));
|
||||||
|
|
||||||
if (!m.isChunked()) {
|
if (!m.isChunked()) {
|
||||||
ChannelBuffer content = m.getContent();
|
ChannelBuffer content = m.getContent();
|
||||||
// Encode the content.
|
// Encode the content.
|
||||||
content = ChannelBuffers.wrappedBuffer(
|
content = ChannelBuffers.wrappedBuffer(
|
||||||
encode(content), finishEncode());
|
encode(content), finishEncode());
|
||||||
|
|
||||||
// Replace the content.
|
// Replace the content.
|
||||||
m.setContent(content);
|
m.setContent(content);
|
||||||
if (m.containsHeader(HttpHeaders.Names.CONTENT_LENGTH)) {
|
if (m.containsHeader(HttpHeaders.Names.CONTENT_LENGTH)) {
|
||||||
m.setHeader(
|
m.setHeader(
|
||||||
HttpHeaders.Names.CONTENT_LENGTH,
|
HttpHeaders.Names.CONTENT_LENGTH,
|
||||||
Integer.toString(content.readableBytes()));
|
Integer.toString(content.readableBytes()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Because HttpMessage is a mutable object, we can simply forward the write request.
|
// Because HttpMessage is a mutable object, we can simply forward the write request.
|
||||||
ctx.sendDownstream(e);
|
ctx.sendDownstream(e);
|
||||||
|
}
|
||||||
} else if (msg instanceof HttpChunk) {
|
} else if (msg instanceof HttpChunk) {
|
||||||
HttpChunk c = (HttpChunk) msg;
|
HttpChunk c = (HttpChunk) msg;
|
||||||
ChannelBuffer content = c.getContent();
|
ChannelBuffer content = c.getContent();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user