Package io.netty.handler.codec.http
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
public abstract class HttpContentDecoder extends MessageToMessageDecoder<HttpObject>
Decodes the content of the receivedHttpRequestandHttpContent. The original content is replaced with the new content decoded by theEmbeddedChannel, which is created bynewContentDecoder(String). Once decoding is finished, the value of the 'Content-Encoding' header is set to the target content encoding, as returned bygetTargetContentEncoding(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 returnnullso 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 ofHttpContentDecompressor.This handler must be placed after
HttpObjectDecoderin the pipeline so that this handler can intercept HTTP requests afterHttpObjectDecoderconvertsByteBufs into HTTP requests.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description protected ChannelHandlerContextctx
-
Constructor Summary
Constructors Constructor Description HttpContentDecoder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidchannelInactive(ChannelHandlerContext ctx)CallsChannelHandlerContext.fireChannelInactive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidchannelReadComplete(ChannelHandlerContext ctx)CallsChannelHandlerContext.fireChannelReadComplete()to forward to the nextChannelInboundHandlerin theChannelPipeline.protected voiddecode(ChannelHandlerContext ctx, HttpObject msg, java.util.List<java.lang.Object> out)Decode from one message to an other.protected java.lang.StringgetTargetContentEncoding(java.lang.String contentEncoding)Returns the expected content encoding of the decoded content.voidhandlerAdded(ChannelHandlerContext ctx)Do nothing by default, sub-classes may override this method.voidhandlerRemoved(ChannelHandlerContext ctx)Do nothing by default, sub-classes may override this method.protected abstract EmbeddedChannelnewContentDecoder(java.lang.String contentEncoding)Returns a newEmbeddedChannelthat decodes the HTTP message content encoded in the specified contentEncoding.-
Methods inherited from class io.netty.handler.codec.MessageToMessageDecoder
acceptInboundMessage, channelRead
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
-
-
-
Field Detail
-
ctx
protected ChannelHandlerContext ctx
-
-
Method Detail
-
decode
protected void decode(ChannelHandlerContext ctx, HttpObject msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
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:
java.lang.Exception- is thrown if an error occurs
-
channelReadComplete
public void channelReadComplete(ChannelHandlerContext ctx) throws java.lang.Exception
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:
java.lang.Exception
-
newContentDecoder
protected abstract EmbeddedChannel newContentDecoder(java.lang.String contentEncoding) throws java.lang.Exception
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:
java.lang.Exception
-
getTargetContentEncoding
protected java.lang.String getTargetContentEncoding(java.lang.String contentEncoding) throws java.lang.ExceptionReturns 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:
java.lang.Exception
-
handlerRemoved
public void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerRemovedin interfaceChannelHandler- Overrides:
handlerRemovedin classChannelHandlerAdapter- Throws:
java.lang.Exception
-
channelInactive
public void channelInactive(ChannelHandlerContext ctx) throws java.lang.Exception
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:
java.lang.Exception
-
handlerAdded
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerAddedin interfaceChannelHandler- Overrides:
handlerAddedin classChannelHandlerAdapter- Throws:
java.lang.Exception
-
-