@Override
protected void encode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out)
throws Exception {
if (msg instanceof HttpResponse) {
HttpResponse res = (HttpResponse) msg;
skipCompression = false;
// if an "content-encoding: identity" header was set, we do not compress
if (skipCompression = res.headers().containsValue(
HttpHeaderNames.CONTENT_ENCODING,
HttpHeaderValues.IDENTITY,
true)) {
// remove header as one should not send Identity as content encoding
res.headers().remove(HttpHeaderNames.CONTENT_ENCODING);
} else {
CharSequence mimeType = HttpUtil.getMimeType(res);
// skip compression if the media type is not compressible by the server
skipCompression = mimeType != null && !isCompressable(MediaType.parse(mimeType.toString()));
// skip compression if the content length is less than expected by the server
int contentLength = res.headers().getInt(HttpHeaderNames.CONTENT_LENGTH, 0);
skipCompression = contentLength > 0 && contentLength < compressionContentLength;
}
}
super.encode(ctx, msg, out);
}
CustomHttpContentCompressor.java 文件源码
java
阅读 25
收藏 0
点赞 0
评论 0
项目:restnext
作者:
评论列表
文章目录