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
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 ByteBuf
s into HTTP requests.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
protected ChannelHandlerContext
private EmbeddedChannel
(package private) static final String
private boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
CallsChannelHandlerContext.fireChannelInactive()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
CallsChannelHandlerContext.fireChannelReadComplete()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.private void
cleanup()
private void
private void
protected void
decode
(ChannelHandlerContext ctx, HttpObject msg, List<Object> out) Decode from one message to an other.private void
decodeContent
(HttpContent c, List<Object> out) private void
fetchDecoderOutput
(List<Object> out) private void
finishDecode
(List<Object> out) protected String
getTargetContentEncoding
(String contentEncoding) Returns the expected content encoding of the decoded content.void
Do nothing by default, sub-classes may override this method.void
Do nothing by default, sub-classes may override this method.protected abstract EmbeddedChannel
newContentDecoder
(String contentEncoding) Returns a newEmbeddedChannel
that 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 Details
-
IDENTITY
-
ctx
-
decoder
-
continueResponse
private boolean continueResponse -
needRead
private boolean needRead
-
-
Constructor Details
-
HttpContentDecoder
public HttpContentDecoder()
-
-
Method Details
-
decode
Description copied from class:MessageToMessageDecoder
Decode from one message to an other. This method will be called for each written message that can be handled by this decoder.- Specified by:
decode
in classMessageToMessageDecoder<HttpObject>
- Parameters:
ctx
- theChannelHandlerContext
which thisMessageToMessageDecoder
belongs tomsg
- the message to decode to an other oneout
- theList
to which decoded messages should be added- Throws:
Exception
- is thrown if an error occurs
-
decodeContent
-
channelReadComplete
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelReadComplete()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelReadComplete
in interfaceChannelInboundHandler
- Overrides:
channelReadComplete
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
newContentDecoder
Returns a newEmbeddedChannel
that decodes the HTTP message content encoded in the specified contentEncoding.- Parameters:
contentEncoding
- the value of the"Content-Encoding"
header- Returns:
- a new
EmbeddedChannel
if the specified encoding is supported.null
otherwise (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:ChannelHandlerAdapter
Do nothing by default, sub-classes may override this method.- Specified by:
handlerRemoved
in interfaceChannelHandler
- Overrides:
handlerRemoved
in classChannelHandlerAdapter
- Throws:
Exception
-
channelInactive
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelInactive()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelInactive
in interfaceChannelInboundHandler
- Overrides:
channelInactive
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
handlerAdded
Description copied from class:ChannelHandlerAdapter
Do nothing by default, sub-classes may override this method.- Specified by:
handlerAdded
in interfaceChannelHandler
- Overrides:
handlerAdded
in classChannelHandlerAdapter
- Throws:
Exception
-
cleanup
private void cleanup() -
cleanupSafely
-
decode
-
finishDecode
-
fetchDecoderOutput
-