Class HttpContentEncoder
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
- All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler
- Direct Known Subclasses:
HttpContentCompressor
Encodes the content of the outbound
HttpResponse and HttpContent.
The original content is replaced with the new content encoded by the
EmbeddedChannel, which is created by beginEncode(HttpResponse, String).
Once encoding is finished, the value of the 'Content-Encoding' header
is set to the target content encoding, as returned by
beginEncode(HttpResponse, String).
Also, the 'Content-Length' header is updated to the length of the
encoded content. If there is no supported or allowed encoding in the
corresponding HttpRequest's "Accept-Encoding" header,
beginEncode(HttpResponse, String) should return null so that
no encoding occurs (i.e. pass-through).
Please note that this is an abstract class. You have to extend this class
and implement beginEncode(HttpResponse, String) properly to make
this class functional. For example, refer to the source code of
HttpContentCompressor.
This handler must be placed after HttpObjectEncoder in the pipeline
so that this handler can intercept HTTP responses before HttpObjectEncoder
converts them into ByteBufs.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanacceptOutboundMessage(Object msg) Returnstrueif and only if the specified message can be encoded by this codec.protected abstract HttpContentEncoder.ResultbeginEncode(HttpResponse httpResponse, String acceptEncoding) Prepare to encode the HTTP message content.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, writeMethods inherited from class ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, readMethods inherited from class ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, handlerAdded, isSharableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChannelHandler
handlerAdded
-
Constructor Details
-
HttpContentEncoder
public HttpContentEncoder()
-
-
Method Details
-
acceptOutboundMessage
Description copied from class:MessageToMessageCodecReturnstrueif and only if the specified message can be encoded by this codec.- Overrides:
acceptOutboundMessagein classMessageToMessageCodec<HttpRequest, HttpObject>- Parameters:
msg- the message- Throws:
Exception
-
decode
protected void decode(ChannelHandlerContext ctx, HttpRequest msg, List<Object> out) throws Exception - Specified by:
decodein classMessageToMessageCodec<HttpRequest, HttpObject>- Throws:
Exception- See Also:
-
encode
- Specified by:
encodein classMessageToMessageCodec<HttpRequest, HttpObject>- Throws:
Exception- See Also:
-
beginEncode
protected abstract HttpContentEncoder.Result beginEncode(HttpResponse httpResponse, String acceptEncoding) throws Exception Prepare to encode the HTTP message content.- 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
-
handlerRemoved
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerRemovedin interfaceChannelHandler- Overrides:
handlerRemovedin classChannelHandlerAdapter- Throws:
Exception
-
channelInactive
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelInactive()to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelInactivein interfaceChannelInboundHandler- Overrides:
channelInactivein classChannelInboundHandlerAdapter- Throws:
Exception
-