Top Description Fields Constructors Methods
io.netty.handler.codec.http

public abstract Class HttpContentDecoder

extends MessageToMessageDecoder<HttpObject>
Class Inheritance
Known Direct Subclasses
io.netty.handler.codec.http.HttpContentDecompressor
Imports
io.netty.buffer.ByteBuf, io.netty.channel.ChannelHandlerContext, io.netty.channel.embedded.EmbeddedChannel, io.netty.handler.codec.CodecException, .DecoderResult, .MessageToMessageDecoder, io.netty.util.ReferenceCountUtil, java.util.List

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 ByteBufs into HTTP requests.

Field Summary

Modifier and TypeField and Description
private boolean
protected ChannelHandlerContext
private EmbeddedChannel
pack-priv static final String
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
private void
private void
protected void
decode(ChannelHandlerContext ctx, HttpObject
the message to decode to an other one
msg
,
List<Object>
the List to which decoded messages should be added
out
)

Implements abstract io.netty.handler.codec.MessageToMessageDecoder.decode.

Decode from one message to an other.
private void
private void
private void
private void
protected String

Returns:

the expected content encoding of the new content
getTargetContentEncoding
(String
the value of the "Content-Encoding" header
contentEncoding
)

Returns the expected content encoding of the decoded content.

public void
handlerAdded(ChannelHandlerContext ctx)

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.
public void
handlerRemoved(ChannelHandlerContext ctx)

Overrides io.netty.channel.ChannelHandlerAdapter.handlerRemoved.

Implements io.netty.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.
protected abstract EmbeddedChannel

Returns:

a new EmbeddedChannel if the specified encoding is supported. null otherwise (alternatively, you can throw an exception to block unknown encoding).
newContentDecoder
(String
the value of the "Content-Encoding" header
contentEncoding
)

Returns a new EmbeddedChannel that decodes the HTTP message content encoded in the specified contentEncoding.

Inherited from io.netty.handler.codec.MessageToMessageDecoder:
acceptInboundMessagechannelRead

Field Detail

continueResponseback to summary
private boolean continueResponse
ctxback to summary
protected ChannelHandlerContext ctx
decoderback to summary
private EmbeddedChannel decoder
IDENTITYback to summary
pack-priv static final String IDENTITY
needReadback to summary
private boolean needRead

Constructor Detail

HttpContentDecoderback to summary
public HttpContentDecoder()

Method Detail

channelInactiveback to summary
public void channelInactive(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelInactive.

Implements io.netty.channel.ChannelInboundHandler.channelInactive.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelInactive.

Calls ChannelHandlerContext#fireChannelInactive() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
channelReadCompleteback to summary
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete.

Implements io.netty.channel.ChannelInboundHandler.channelReadComplete.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete.

Calls ChannelHandlerContext#fireChannelReadComplete() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
cleanupback to summary
private void cleanup()
cleanupSafelyback to summary
private void cleanupSafely(ChannelHandlerContext ctx)
decodeback to summary
protected void decode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out) throws Exception

Implements abstract io.netty.handler.codec.MessageToMessageDecoder.decode.

Doc from io.netty.handler.codec.MessageToMessageDecoder.decode.

Decode from one message to an other. This method will be called for each written message that can be handled by this decoder.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageDecoder belongs to

msg:HttpObject

the message to decode to an other one

out:List<Object>

the List to which decoded messages should be added

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
decodeback to summary
private void decode(ByteBuf in, List<Object> out)
decodeContentback to summary
private void decodeContent(HttpContent c, List<Object> out)
fetchDecoderOutputback to summary
private void fetchDecoderOutput(List<Object> out)
finishDecodeback to summary
private void finishDecode(List<Object> out)
getTargetContentEncodingback to summary
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:String

the value of the "Content-Encoding" header

Returns:String

the expected content encoding of the new content

handlerAddedback to summary
public void handlerAdded(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Doc from io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.

Annotations
@Override
handlerRemovedback to summary
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.handlerRemoved.

Implements io.netty.channel.ChannelHandler.handlerRemoved.

Doc from io.netty.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.

Annotations
@Override
newContentDecoderback to summary
protected abstract EmbeddedChannel newContentDecoder(String contentEncoding) throws Exception

Returns a new EmbeddedChannel that decodes the HTTP message content encoded in the specified contentEncoding.

Parameters
contentEncoding:String

the value of the "Content-Encoding" header

Returns:EmbeddedChannel

a new EmbeddedChannel if the specified encoding is supported. null otherwise (alternatively, you can throw an exception to block unknown encoding).