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:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelInboundHandler
- Direct Known Subclasses:
HttpContentDecompressor
public abstract class HttpContentDecoder extends io.netty.handler.codec.MessageToMessageDecoder<HttpObject>
Decodes the content of the receivedHttpRequest
andHttpContent
. 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 returnnull
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 ofHttpContentDecompressor
.This handler must be placed after
HttpObjectDecoder
in the pipeline so that this handler can intercept HTTP requests afterHttpObjectDecoder
convertsByteBuf
s into HTTP requests.
-
-
Field Summary
Fields Modifier and Type Field Description protected io.netty.channel.ChannelHandlerContext
ctx
-
Constructor Summary
Constructors Constructor Description HttpContentDecoder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
channelInactive(io.netty.channel.ChannelHandlerContext ctx)
void
channelReadComplete(io.netty.channel.ChannelHandlerContext ctx)
protected void
decode(io.netty.channel.ChannelHandlerContext ctx, HttpObject msg, List<Object> out)
protected String
getTargetContentEncoding(String contentEncoding)
Returns the expected content encoding of the decoded content.void
handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
void
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
protected abstract io.netty.channel.embedded.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
-
-
-
-
Method Detail
-
decode
protected void decode(io.netty.channel.ChannelHandlerContext ctx, HttpObject msg, List<Object> out) throws Exception
- Specified by:
decode
in classio.netty.handler.codec.MessageToMessageDecoder<HttpObject>
- Throws:
Exception
-
channelReadComplete
public void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) throws Exception
- Specified by:
channelReadComplete
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelReadComplete
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
Exception
-
newContentDecoder
protected abstract io.netty.channel.embedded.EmbeddedChannel newContentDecoder(String contentEncoding) throws Exception
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
protected String getTargetContentEncoding(String contentEncoding) throws Exception
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
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception
- Specified by:
handlerRemoved
in interfaceio.netty.channel.ChannelHandler
- Overrides:
handlerRemoved
in classio.netty.channel.ChannelHandlerAdapter
- Throws:
Exception
-
channelInactive
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
- Specified by:
channelInactive
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelInactive
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
Exception
-
-