Not try to compresses HttpMessage if IDENTITY header value is set.
Motivation: If Content-Encoding: IDENTITY is used we should not try to compress the http message but just let it pass-through. Modifications: Remove "!" Result: Fixes [#6689]
This commit is contained in:
parent
3cc4052963
commit
a3e496a521
@ -101,8 +101,7 @@ public class HttpContentCompressor extends HttpContentEncoder {
|
|||||||
@Override
|
@Override
|
||||||
protected Result beginEncode(HttpResponse headers, String acceptEncoding) throws Exception {
|
protected Result beginEncode(HttpResponse headers, String acceptEncoding) throws Exception {
|
||||||
String contentEncoding = headers.headers().get(HttpHeaderNames.CONTENT_ENCODING);
|
String contentEncoding = headers.headers().get(HttpHeaderNames.CONTENT_ENCODING);
|
||||||
if (contentEncoding != null &&
|
if (HttpHeaderValues.IDENTITY.contentEqualsIgnoreCase(contentEncoding)) {
|
||||||
!HttpHeaderValues.IDENTITY.contentEqualsIgnoreCase(contentEncoding)) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,6 +373,28 @@ public class HttpContentCompressorTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIdentity() throws Exception {
|
||||||
|
EmbeddedChannel ch = new EmbeddedChannel(new HttpContentCompressor());
|
||||||
|
assertTrue(ch.writeInbound(newRequest()));
|
||||||
|
|
||||||
|
FullHttpResponse res = new DefaultFullHttpResponse(
|
||||||
|
HttpVersion.HTTP_1_1, HttpResponseStatus.OK,
|
||||||
|
Unpooled.copiedBuffer("Hello, World", CharsetUtil.US_ASCII));
|
||||||
|
int len = res.content().readableBytes();
|
||||||
|
res.headers().set(HttpHeaderNames.CONTENT_LENGTH, len);
|
||||||
|
res.headers().set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.IDENTITY);
|
||||||
|
assertTrue(ch.writeOutbound(res));
|
||||||
|
|
||||||
|
FullHttpResponse response = (FullHttpResponse) ch.readOutbound();
|
||||||
|
assertEquals(String.valueOf(len), response.headers().get(HttpHeaderNames.CONTENT_LENGTH));
|
||||||
|
assertEquals(HttpHeaderValues.IDENTITY.toString(), response.headers().get(HttpHeaderNames.CONTENT_ENCODING));
|
||||||
|
assertEquals("Hello, World", response.content().toString(CharsetUtil.US_ASCII));
|
||||||
|
response.release();
|
||||||
|
|
||||||
|
assertTrue(ch.finishAndReleaseAll());
|
||||||
|
}
|
||||||
|
|
||||||
private static FullHttpRequest newRequest() {
|
private static FullHttpRequest newRequest() {
|
||||||
FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
|
FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
|
||||||
req.headers().set(HttpHeaderNames.ACCEPT_ENCODING, "gzip");
|
req.headers().set(HttpHeaderNames.ACCEPT_ENCODING, "gzip");
|
||||||
|
Loading…
Reference in New Issue
Block a user