public abstract class HttpContentDecoder extends io.netty.handler.codec.MessageToMessageDecoder<HttpObject>
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.
Modifier and Type | Field and Description |
---|---|
protected io.netty.channel.ChannelHandlerContext |
ctx |
Constructor and Description |
---|
HttpContentDecoder() |
Modifier and Type | Method and Description |
---|---|
void |
channelInactive(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 new
EmbeddedChannel that decodes the HTTP message
content encoded in the specified contentEncoding. |
acceptInboundMessage, channelRead
protected void decode(io.netty.channel.ChannelHandlerContext ctx, HttpObject msg, List<Object> out) throws Exception
decode
in class io.netty.handler.codec.MessageToMessageDecoder<HttpObject>
Exception
protected abstract io.netty.channel.embedded.EmbeddedChannel newContentDecoder(String contentEncoding) throws Exception
EmbeddedChannel
that decodes the HTTP message
content encoded in the specified contentEncoding.contentEncoding
- the value of the "Content-Encoding"
headerEmbeddedChannel
if the specified encoding is supported.
null
otherwise (alternatively, you can throw an exception
to block unknown encoding).Exception
protected String getTargetContentEncoding(String contentEncoding) throws Exception
"identity"
by default, which is the case for
most decoders.contentEncoding
- the value of the "Content-Encoding"
headerException
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception
handlerRemoved
in interface io.netty.channel.ChannelHandler
handlerRemoved
in class io.netty.channel.ChannelHandlerAdapter
Exception
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelInactive
in interface io.netty.channel.ChannelInboundHandler
channelInactive
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
Copyright © 2008–2017 The Netty Project. All rights reserved.