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:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

public class HttpContentCompressor extends HttpContentEncoder
Compresses an 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.
  • 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

    io.netty.channel.ChannelHandler.Sharable
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new handler with the default compression level (6), default window size (15) and default memory level (8).
    HttpContentCompressor(int compressionLevel)
    Deprecated.
    HttpContentCompressor(int compressionLevel, int windowBits, int memLevel)
    Deprecated.
    HttpContentCompressor(int compressionLevel, int windowBits, int memLevel, int contentSizeThreshold)
    Deprecated.
    HttpContentCompressor(int contentSizeThreshold, io.netty.handler.codec.compression.CompressionOptions... compressionOptions)
    Create a new HttpContentCompressor instance with specified CompressionOptionss
    HttpContentCompressor(io.netty.handler.codec.compression.CompressionOptions... compressionOptions)
    Create a new HttpContentCompressor Instance with specified CompressionOptionss and contentSizeThreshold set to 0
  • Method Summary

    Modifier and Type
    Method
    Description
    beginEncode(HttpResponse httpResponse, String acceptEncoding)
    Prepare to encode the HTTP message content.
    protected String
    determineEncoding(String acceptEncoding)
     
    protected io.netty.handler.codec.compression.ZlibWrapper
    determineWrapper(String acceptEncoding)
    Deprecated.
    void
    handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
     

    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HttpContentCompressor

      public HttpContentCompressor()
      Creates a new handler with the default compression level (6), default window size (15) and default memory level (8).
    • HttpContentCompressor

      @Deprecated public HttpContentCompressor(int compressionLevel)
      Deprecated.
      Creates a new handler with the specified compression level, default window size (15) and default memory level (8).
      Parameters:
      compressionLevel - 1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
    • HttpContentCompressor

      @Deprecated public HttpContentCompressor(int compressionLevel, int windowBits, int memLevel)
      Deprecated.
      Creates a new handler with the specified compression level, window size, and memory level..
      Parameters:
      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
    • HttpContentCompressor

      @Deprecated public HttpContentCompressor(int compressionLevel, int windowBits, int memLevel, int contentSizeThreshold)
      Deprecated.
      Creates a new handler with the specified compression level, window size, and memory level..
      Parameters:
      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
      contentSizeThreshold - 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.
    • HttpContentCompressor

      public HttpContentCompressor(io.netty.handler.codec.compression.CompressionOptions... compressionOptions)
      Create a new HttpContentCompressor Instance with specified CompressionOptionss and contentSizeThreshold set to 0
      Parameters:
      compressionOptions - CompressionOptions or null if the default should be used.
    • HttpContentCompressor

      public HttpContentCompressor(int contentSizeThreshold, io.netty.handler.codec.compression.CompressionOptions... compressionOptions)
      Create a new HttpContentCompressor instance with specified CompressionOptionss
      Parameters:
      contentSizeThreshold - 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.
  • Method Details

    • handlerAdded

      public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      handlerAdded in interface io.netty.channel.ChannelHandler
      Overrides:
      handlerAdded in class io.netty.channel.ChannelHandlerAdapter
      Throws:
      Exception
    • beginEncode

      protected HttpContentEncoder.Result beginEncode(HttpResponse httpResponse, String acceptEncoding) throws Exception
      Description copied from class: HttpContentEncoder
      Prepare to encode the HTTP message content.
      Specified by:
      beginEncode in class HttpContentEncoder
      Parameters:
      httpResponse - the http response
      acceptEncoding - the value of the "Accept-Encoding" header
      Returns:
      the result of preparation, which is composed of the determined target content encoding and a new EmbeddedChannel 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).
      Throws:
      Exception
    • determineEncoding

      protected String determineEncoding(String acceptEncoding)
    • determineWrapper

      @Deprecated protected io.netty.handler.codec.compression.ZlibWrapper determineWrapper(String acceptEncoding)
      Deprecated.