Package io.netty.handler.codec.http
Class HttpContentCompressor
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.channel.ChannelDuplexHandler
-
- io.netty.handler.codec.MessageToMessageCodec<HttpRequest,HttpObject>
-
- io.netty.handler.codec.http.HttpContentEncoder
-
- io.netty.handler.codec.http.HttpContentCompressor
-
- All Implemented Interfaces:
ChannelHandler,ChannelInboundHandler,ChannelOutboundHandler
public class HttpContentCompressor extends HttpContentEncoder
Compresses anHttpMessageand anHttpContentingzipordeflateencoding while respecting the"Accept-Encoding"header. If there is no matching encoding, no compression is done. For more information on how this handler modifies the message, please refer toHttpContentEncoder.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.netty.handler.codec.http.HttpContentEncoder
HttpContentEncoder.Result
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description private intcompressionLevelprivate intcontentSizeThresholdprivate ChannelHandlerContextctxprivate intmemLevelprivate intwindowBits
-
Constructor Summary
Constructors Constructor Description HttpContentCompressor()Creates a new handler with the default compression level (6), default window size (15) and default memory level (8).HttpContentCompressor(int compressionLevel)Creates a new handler with the specified compression level, default window size (15) and default memory level (8).HttpContentCompressor(int compressionLevel, int windowBits, int memLevel)Creates a new handler with the specified compression level, window size, and memory level..HttpContentCompressor(int compressionLevel, int windowBits, int memLevel, int contentSizeThreshold)Creates a new handler with the specified compression level, window size, and memory level..
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected HttpContentEncoder.ResultbeginEncode(HttpResponse httpResponse, java.lang.String acceptEncoding)Prepare to encode the HTTP message content.protected ZlibWrapperdetermineWrapper(java.lang.String acceptEncoding)voidhandlerAdded(ChannelHandlerContext ctx)Do nothing by default, sub-classes may override this method.-
Methods inherited from class io.netty.handler.codec.http.HttpContentEncoder
acceptOutboundMessage, channelInactive, decode, encode, handlerRemoved
-
Methods inherited from class io.netty.handler.codec.MessageToMessageCodec
acceptInboundMessage, channelRead, write
-
Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, read
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
-
-
-
Field Detail
-
compressionLevel
private final int compressionLevel
-
windowBits
private final int windowBits
-
memLevel
private final int memLevel
-
contentSizeThreshold
private final int contentSizeThreshold
-
ctx
private ChannelHandlerContext ctx
-
-
Constructor Detail
-
HttpContentCompressor
public HttpContentCompressor()
Creates a new handler with the default compression level (6), default window size (15) and default memory level (8).
-
HttpContentCompressor
public HttpContentCompressor(int compressionLevel)
Creates a new handler with the specified compression level, default window size (15) and default memory level (8).- Parameters:
compressionLevel-1yields the fastest compression and9yields the best compression.0means no compression. The default compression level is6.
-
HttpContentCompressor
public HttpContentCompressor(int compressionLevel, int windowBits, int memLevel)Creates a new handler with the specified compression level, window size, and memory level..- Parameters:
compressionLevel-1yields the fastest compression and9yields the best compression.0means no compression. The default compression level is6.windowBits- The base two logarithm of the size of the history buffer. The value should be in the range9to15inclusive. Larger values result in better compression at the expense of memory usage. The default value is15.memLevel- How much memory should be allocated for the internal compression state.1uses minimum memory and9uses maximum memory. Larger values result in better and faster compression at the expense of memory usage. The default value is8
-
HttpContentCompressor
public HttpContentCompressor(int compressionLevel, int windowBits, int memLevel, int contentSizeThreshold)Creates a new handler with the specified compression level, window size, and memory level..- Parameters:
compressionLevel-1yields the fastest compression and9yields the best compression.0means no compression. The default compression level is6.windowBits- The base two logarithm of the size of the history buffer. The value should be in the range9to15inclusive. Larger values result in better compression at the expense of memory usage. The default value is15.memLevel- How much memory should be allocated for the internal compression state.1uses minimum memory and9uses maximum memory. Larger values result in better and faster compression at the expense of memory usage. The default value is8contentSizeThreshold- The response body is compressed when the size of the response body exceeds the threshold. The value should be a non negative number.0will enable compression for all responses.
-
-
Method Detail
-
handlerAdded
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerAddedin interfaceChannelHandler- Overrides:
handlerAddedin classChannelHandlerAdapter- Throws:
java.lang.Exception
-
beginEncode
protected HttpContentEncoder.Result beginEncode(HttpResponse httpResponse, java.lang.String acceptEncoding) throws java.lang.Exception
Description copied from class:HttpContentEncoderPrepare to encode the HTTP message content.- Specified by:
beginEncodein classHttpContentEncoder- Parameters:
httpResponse- the http responseacceptEncoding- the value of the"Accept-Encoding"header- Returns:
- the result of preparation, which is composed of the determined
target content encoding and a new
EmbeddedChannelthat encodes the content into the target content encoding.nullifacceptEncodingis unsupported or rejected and thus the content should be handled as-is (i.e. no encoding). - Throws:
java.lang.Exception
-
determineWrapper
protected ZlibWrapper determineWrapper(java.lang.String acceptEncoding)
-
-