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
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 HttpContentEncoder
HttpContentEncoder.ResultNested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.SharableModifier and TypeInterfaceDescriptionstatic @interfaceIndicates that the same instance of the annotatedChannelHandlercan be added to one or moreChannelPipelines multiple times without a race condition. -
Field Summary
Fields inherited from class HttpContentEncoder
DEFAULT_MAX_PIPELINE_DEPTH -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new handler withStandardCompressionOptions.brotli()(if supported) ,StandardCompressionOptions.zstd()(if supported),StandardCompressionOptions.snappy(),StandardCompressionOptions.gzip()andStandardCompressionOptions.deflate().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, int maxPipelineDepth, CompressionOptions... compressionOptions) Create a newHttpContentCompressorinstance with specifiedCompressionOptionssHttpContentCompressor(int contentSizeThreshold, CompressionOptions... compressionOptions) Create a newHttpContentCompressorinstance with specifiedCompressionOptionssHttpContentCompressor(CompressionOptions... compressionOptions) Create a newHttpContentCompressorInstance with specifiedCompressionOptionss and contentSizeThreshold set to0 -
Method Summary
Modifier and TypeMethodDescriptionprotected HttpContentEncoder.ResultbeginEncode(HttpResponse httpResponse, String acceptEncoding) Prepare to encode the HTTP message content.protected StringdetermineEncoding(String acceptEncoding) protected ZlibWrapperdetermineWrapper(String acceptEncoding) Deprecated.voidDo nothing by default, sub-classes may override this method.Methods inherited from class HttpContentEncoder
acceptOutboundMessage, channelInactive, decode, encode, handlerRemovedModifier and TypeMethodDescriptionbooleanReturnstrueif and only if the specified message can be encoded by this codec.voidCallsChannelHandlerContext.fireChannelInactive()to forward to the nextChannelInboundHandlerin theChannelPipeline.protected voiddecode(ChannelHandlerContext ctx, HttpRequest msg, List<Object> out) protected voidencode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out) voidDo nothing by default, sub-classes may override this method.Methods inherited from class MessageToMessageCodec
acceptInboundMessage, channelRead, channelReadComplete, writeModifier and TypeMethodDescriptionbooleanReturnstrueif and only if the specified message can be decoded by this codec.voidchannelRead(ChannelHandlerContext ctx, Object msg) CallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelReadComplete()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidwrite(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) CallsChannelOutboundInvoker.write(Object, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.Methods inherited from class ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, readModifier and TypeMethodDescriptionvoidbind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) CallsChannelOutboundInvoker.bind(SocketAddress, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidclose(ChannelHandlerContext ctx, ChannelPromise promise) CallsChannelOutboundInvoker.close(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidconnect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) CallsChannelOutboundInvoker.connect(SocketAddress, SocketAddress, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidderegister(ChannelHandlerContext ctx, ChannelPromise promise) CallsChannelOutboundInvoker.deregister(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voiddisconnect(ChannelHandlerContext ctx, ChannelPromise promise) CallsChannelOutboundInvoker.disconnect(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.flush()to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.read()to forward to the nextChannelOutboundHandlerin theChannelPipeline.Methods inherited from class ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredModifier and TypeMethodDescriptionvoidCallsChannelHandlerContext.fireChannelActive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelRegistered()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelUnregistered()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelWritabilityChanged()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidexceptionCaught(ChannelHandlerContext ctx, Throwable cause) CallsChannelHandlerContext.fireExceptionCaught(Throwable)to forward to the nextChannelHandlerin theChannelPipeline.voiduserEventTriggered(ChannelHandlerContext ctx, Object evt) CallsChannelHandlerContext.fireUserEventTriggered(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.Methods inherited from class ChannelHandlerAdapter
ensureNotSharable, isSharableModifier and TypeMethodDescriptionprotected voidbooleanReturntrueif the implementation isChannelHandler.Sharableand so can be added to differentChannelPipelines.
-
Constructor Details
-
HttpContentCompressor
public HttpContentCompressor()Creates a new handler withStandardCompressionOptions.brotli()(if supported) ,StandardCompressionOptions.zstd()(if supported),StandardCompressionOptions.snappy(),StandardCompressionOptions.gzip()andStandardCompressionOptions.deflate(). -
HttpContentCompressor
Deprecated.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
Deprecated.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
@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-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.
-
HttpContentCompressor
Create a newHttpContentCompressorInstance with specifiedCompressionOptionss and contentSizeThreshold set to0- Parameters:
compressionOptions-CompressionOptionsornullif the default should be used.
-
HttpContentCompressor
Create a newHttpContentCompressorinstance with specifiedCompressionOptionss- 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.0will enable compression for all responses.compressionOptions-CompressionOptionsornullif the default should be used.
-
HttpContentCompressor
public HttpContentCompressor(int contentSizeThreshold, int maxPipelineDepth, CompressionOptions... compressionOptions) Create a newHttpContentCompressorinstance with specifiedCompressionOptionss- 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.0will enable compression for all responses.maxPipelineDepth- The maximum allowed depth of the encoding pipeline queue, the default value is set toHttpContentEncoder.DEFAULT_MAX_PIPELINE_DEPTHcompressionOptions-CompressionOptionsornullif the default should be used.
-
-
Method Details
-
handlerAdded
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerAddedin interfaceChannelHandler- Overrides:
handlerAddedin classChannelHandlerAdapter- Throws:
Exception
-
beginEncode
protected HttpContentEncoder.Result beginEncode(HttpResponse httpResponse, String acceptEncoding) throws 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:
Exception
-
determineEncoding
-
determineWrapper
Deprecated.
-