public class HttpContentCompressor extends HttpContentEncoder
HttpMessage and an HttpContent in gzip or
 deflate encoding 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 to
 HttpContentEncoder.HttpContentEncoder.ResultChannelHandler.Sharable| Constructor and Description | 
|---|
| HttpContentCompressor()Creates a new handler with  StandardCompressionOptions.brotli()(if supported) ,StandardCompressionOptions.zstd()(if supported),StandardCompressionOptions.snappy(),StandardCompressionOptions.gzip()andStandardCompressionOptions.deflate(). | 
| HttpContentCompressor(CompressionOptions... compressionOptions)Create a new  HttpContentCompressorInstance with specifiedCompressionOptionss and contentSizeThreshold set to0 | 
| HttpContentCompressor(int compressionLevel)Deprecated.  | 
| HttpContentCompressor(int contentSizeThreshold,
                     CompressionOptions... compressionOptions)Create a new  HttpContentCompressorinstance with specifiedCompressionOptionss | 
| HttpContentCompressor(int compressionLevel,
                     int windowBits,
                     int memLevel)Deprecated.  | 
| HttpContentCompressor(int compressionLevel,
                     int windowBits,
                     int memLevel,
                     int contentSizeThreshold)Deprecated.  | 
| Modifier and Type | Method and Description | 
|---|---|
| protected HttpContentEncoder.Result | beginEncode(HttpResponse httpResponse,
           String acceptEncoding)Prepare to encode the HTTP message content. | 
| protected String | determineEncoding(String acceptEncoding) | 
| protected ZlibWrapper | determineWrapper(String acceptEncoding)Deprecated.  | 
| void | handlerAdded(ChannelHandlerContext ctx)Do nothing by default, sub-classes may override this method. | 
acceptOutboundMessage, channelInactive, decode, encode, handlerRemovedacceptInboundMessage, channelRead, channelReadComplete, writebind, close, connect, deregister, disconnect, flush, readchannelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredensureNotSharable, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexceptionCaughtpublic HttpContentCompressor()
StandardCompressionOptions.brotli() (if supported) ,
 StandardCompressionOptions.zstd() (if supported), StandardCompressionOptions.snappy(),
 StandardCompressionOptions.gzip() and StandardCompressionOptions.deflate().@Deprecated public HttpContentCompressor(int compressionLevel)
compressionLevel - 1 yields the fastest compression and 9 yields the
        best compression.  0 means no compression.  The default
        compression level is 6.@Deprecated public HttpContentCompressor(int compressionLevel, int windowBits, int memLevel)
compressionLevel - 1 yields the fastest compression and 9 yields the
        best compression.  0 means no compression.  The default
        compression level is 6.windowBits - The base two logarithm of the size of the history buffer.  The
        value should be in the range 9 to 15 inclusive.
        Larger values result in better compression at the expense of
        memory usage.  The default value is 15.memLevel - How much memory should be allocated for the internal compression
        state.  1 uses minimum memory and 9 uses maximum
        memory.  Larger values result in better and faster compression
        at the expense of memory usage.  The default value is 8@Deprecated public HttpContentCompressor(int compressionLevel, int windowBits, int memLevel, int contentSizeThreshold)
compressionLevel - 1 yields the fastest compression and 9 yields the
        best compression.  0 means no compression.  The default
        compression level is 6.windowBits - The base two logarithm of the size of the history buffer.  The
        value should be in the range 9 to 15 inclusive.
        Larger values result in better compression at the expense of
        memory usage.  The default value is 15.memLevel - How much memory should be allocated for the internal compression
        state.  1 uses minimum memory and 9 uses maximum
        memory.  Larger values result in better and faster compression
        at the expense of memory usage.  The default value is 8contentSizeThreshold - The response body is compressed when the size of the response
        body exceeds the threshold. The value should be a non negative
        number. 0 will enable compression for all responses.public HttpContentCompressor(CompressionOptions... compressionOptions)
HttpContentCompressor Instance with specified
 CompressionOptionss and contentSizeThreshold set to 0compressionOptions - CompressionOptions or null if the default
        should be used.public HttpContentCompressor(int contentSizeThreshold,
                             CompressionOptions... compressionOptions)
HttpContentCompressor instance with specified
 CompressionOptionsscontentSizeThreshold - The response body is compressed when the size of the response
        body exceeds the threshold. The value should be a non negative
        number. 0 will enable compression for all responses.compressionOptions - CompressionOptions or null
        if the default should be used.public void handlerAdded(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterhandlerAdded in interface ChannelHandlerhandlerAdded in class ChannelHandlerAdapterExceptionprotected HttpContentEncoder.Result beginEncode(HttpResponse httpResponse, String acceptEncoding) throws Exception
HttpContentEncoderbeginEncode in class HttpContentEncoderhttpResponse - the http responseacceptEncoding - the value of the "Accept-Encoding" headerEmbeddedChannel that
         encodes the content into the target content encoding.
         null if acceptEncoding is unsupported or rejected
         and thus the content should be handled as-is (i.e. no encoding).Exception@Deprecated protected ZlibWrapper determineWrapper(String acceptEncoding)
Copyright © 2008–2025 The Netty Project. All rights reserved.