List of usage examples for io.netty.handler.codec.http HttpHeaderValues IDENTITY
AsciiString IDENTITY
To view the source code for io.netty.handler.codec.http HttpHeaderValues IDENTITY.
Click Source Link
From source file:org.restnext.server.CustomHttpContentCompressor.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out) throws Exception { if (msg instanceof HttpResponse) { HttpResponse res = (HttpResponse) msg; skipCompression = false;/* w w w . j a va 2s.c o m*/ // 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); }
From source file:ratpack.server.internal.IgnorableHttpContentCompressor.java
License:Apache License
@SuppressWarnings("deprecation") @Override//from w ww . j a va 2s .c om protected Result beginEncode(HttpResponse res, String acceptEncoding) throws Exception { String contentEncoding = res.headers().getAsString(HttpHeaderConstants.CONTENT_ENCODING); //Allow setting content encoding to identity to skip encoding this supports the Response.noCompress() call. if (HttpHeaderValues.IDENTITY.contentEqualsIgnoreCase(contentEncoding)) { // Remove header as one SHOULD NOT send Identity as content encoding. // This keeps with current behavior there HttpContentCompressor will leave the header in normally. res.headers().remove(HttpHeaderConstants.CONTENT_ENCODING); return null; } return super.beginEncode(res, acceptEncoding); }