Class HttpContentDecoder
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.handler.codec.MessageToMessageDecoder<HttpObject>
io.netty.handler.codec.http.HttpContentDecoder
- All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler
- Direct Known Subclasses:
HttpContentDecompressor
Decodes the content of the received
HttpRequest and HttpContent.
The original content is replaced with the new content decoded by the
EmbeddedChannel, which is created by newContentDecoder(String).
Once decoding is finished, the value of the 'Content-Encoding'
header is set to the target content encoding, as returned by getTargetContentEncoding(String).
Also, the 'Content-Length' header is updated to the length of the
decoded content. If the content encoding of the original is not supported
by the decoder, newContentDecoder(String) should return null
so that no decoding occurs (i.e. pass-through).
Please note that this is an abstract class. You have to extend this class
and implement newContentDecoder(String) properly to make this class
functional. For example, refer to the source code of HttpContentDecompressor.
This handler must be placed after HttpObjectDecoder in the pipeline
so that this handler can intercept HTTP requests after HttpObjectDecoder
converts ByteBufs into HTTP requests.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCallsChannelHandlerContext.fireChannelInactive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelReadComplete()to forward to the nextChannelInboundHandlerin theChannelPipeline.protected voiddecode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out) Decode from one message to an other.protected StringgetTargetContentEncoding(String contentEncoding) Returns the expected content encoding of the decoded content.voidDo nothing by default, sub-classes may override this method.voidDo nothing by default, sub-classes may override this method.protected abstract EmbeddedChannelnewContentDecoder(String contentEncoding) Returns a newEmbeddedChannelthat decodes the HTTP message content encoded in the specified contentEncoding.Methods inherited from class MessageToMessageDecoder
acceptInboundMessage, channelReadMethods inherited from class ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, isSharable
-
Field Details
-
ctx
-
-
Constructor Details
-
HttpContentDecoder
public HttpContentDecoder()
-
-
Method Details
-
decode
Description copied from class:MessageToMessageDecoderDecode from one message to an other. This method will be called for each written message that can be handled by this decoder.- Specified by:
decodein classMessageToMessageDecoder<HttpObject>- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToMessageDecoderbelongs tomsg- the message to decode to an other oneout- theListto which decoded messages should be added- Throws:
Exception- is thrown if an error occurs
-
channelReadComplete
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelReadComplete()to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelReadCompletein interfaceChannelInboundHandler- Overrides:
channelReadCompletein classMessageToMessageDecoder<HttpObject>- Throws:
Exception
-
newContentDecoder
Returns a newEmbeddedChannelthat decodes the HTTP message content encoded in the specified contentEncoding.- Parameters:
contentEncoding- the value of the"Content-Encoding"header- Returns:
- a new
EmbeddedChannelif the specified encoding is supported.nullotherwise (alternatively, you can throw an exception to block unknown encoding). - Throws:
Exception
-
getTargetContentEncoding
Returns the expected content encoding of the decoded content. This getMethod returns"identity"by default, which is the case for most decoders.- Parameters:
contentEncoding- the value of the"Content-Encoding"header- Returns:
- the expected content encoding of the new content
- 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
-
handlerAdded
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerAddedin interfaceChannelHandler- Overrides:
handlerAddedin classChannelHandlerAdapter- Throws:
Exception
-