public abstract class HttpContentDecoder extends io.netty.handler.codec.MessageToMessageDecoder<Object,Object>
HttpRequest
and HttpChunk
.
The original content is replaced with the new content decoded by the
DecoderEmbedder
, 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 HttpMessageDecoder
in the pipeline
so that this handler can intercept HTTP requests after HttpMessageDecoder
converts ByteBuf
s into HTTP requests.
Modifier | Constructor and Description |
---|---|
protected |
HttpContentDecoder()
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
afterRemove(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx) |
Object |
decode(io.netty.channel.ChannelHandlerContext ctx,
Object msg) |
protected String |
getTargetContentEncoding(String contentEncoding)
Returns the expected content encoding of the decoded content.
|
boolean |
isDecodable(Object msg) |
protected abstract io.netty.channel.embedded.EmbeddedByteChannel |
newContentDecoder(String contentEncoding)
Returns a new
DecoderEmbedder that decodes the HTTP message
content encoded in the specified contentEncoding. |
inboundBufferUpdated, newInboundBuffer
afterAdd, beforeAdd, beforeRemove, channelActive, channelRegistered, channelUnregistered, exceptionCaught, userEventTriggered
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public Object decode(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception
protected abstract io.netty.channel.embedded.EmbeddedByteChannel newContentDecoder(String contentEncoding) throws Exception
DecoderEmbedder
that decodes the HTTP message
content encoded in the specified contentEncoding.contentEncoding
- the value of the "Content-Encoding"
headerDecoderEmbedder
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 afterRemove(io.netty.channel.ChannelHandlerContext ctx) throws Exception
afterRemove
in interface io.netty.channel.ChannelHandler
afterRemove
in class io.netty.channel.ChannelStateHandlerAdapter
Exception
Copyright © 2008-2012 The Netty Project. All Rights Reserved.