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

public abstract Class HttpContentDecoder

extends MessageToMessageDecoder<HttpObject>
Class Inheritance
Known Direct Subclasses
io.netty5.handler.codec.http.HttpContentDecompressor
Imports
io.netty5.buffer.Buffer, io.netty5.channel.ChannelHandlerContext, .ChannelOption, io.netty5.handler.codec.CodecException, .MessageToMessageDecoder, io.netty5.handler.codec.compression.Decompressor, io.netty5.handler.codec.http.headers.HttpHeaders, io.netty5.util.AsciiString, .Resource

Decodes the content of the received HttpRequest and HttpContent. The original content is replaced with the new content decoded by the Decompressor, which is created by newContentDecoder(CharSequence). 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(CharSequence) 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(CharSequence) 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 Buffers into HTTP requests.

Field Summary

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

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
channelInactive(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.
public void
channelReadComplete(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelReadComplete.

Invoked when the last message read by the current read operation has been consumed by channelRead(ChannelHandlerContext, Object).
private void
private void
protected void
decodeAndClose(ChannelHandlerContext ctx, HttpObject
the message to decode to another one
msg
)

Overrides io.netty5.handler.codec.MessageToMessageDecoder.decodeAndClose.

Decode from one message to another.
private void
private void
protected String

Returns:

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

Returns the expected content encoding of the decoded content.

public void
handlerAdded(ChannelHandlerContext ctx)

Overrides default io.netty5.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 default io.netty5.channel.ChannelHandler.handlerRemoved.

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

Returns:

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

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

Inherited from io.netty5.handler.codec.MessageToMessageDecoder:
acceptInboundMessagechannelReaddecode

Field Detail

continueResponseback to summary
private boolean continueResponse
ctxback to summary
protected ChannelHandlerContext ctx
decompressorback to summary
private Decompressor decompressor
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 default io.netty5.channel.ChannelHandler.channelInactive.

Doc from io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.

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

Overrides default io.netty5.channel.ChannelHandler.channelReadComplete.

Doc from io.netty5.channel.ChannelHandler.channelReadComplete.

Invoked when the last message read by the current read operation has been consumed by channelRead(ChannelHandlerContext, Object). If ChannelOption#AUTO_READ is off, no further attempt to read an inbound data from the current Channel will be made until ChannelOutboundInvoker#read(ReadBufferAllocator) is called.

Annotations
@Override
cleanupback to summary
private void cleanup()
cleanupSafelyback to summary
private void cleanupSafely(ChannelHandlerContext ctx)
decodeAndCloseback to summary
protected void decodeAndClose(ChannelHandlerContext ctx, HttpObject msg) throws Exception

Overrides io.netty5.handler.codec.MessageToMessageDecoder.decodeAndClose.

Doc from io.netty5.handler.codec.MessageToMessageDecoder.decodeAndClose.

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

The message will not be automatically disposed of after this call. Instead, the responsibility of ensuring that messages are disposed of falls upon the implementor of this method.

Subclasses that wish to have incoming messages automatically disposed of should instead override the decodeAndClose(ChannelHandlerContext, Object) method.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageDecoder belongs to

msg:HttpObject

the message to decode to another one

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
decodeContentback to summary
private void decodeContent(ChannelHandlerContext ctx, HttpContent<?> c)
fireChannelReadback to summary
private void fireChannelRead(ChannelHandlerContext ctx, Object msg)
getTargetContentEncodingback to summary
protected String getTargetContentEncoding(CharSequence 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:CharSequence

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 default io.netty5.channel.ChannelHandler.handlerAdded.

Doc from io.netty5.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 default io.netty5.channel.ChannelHandler.handlerRemoved.

Doc from io.netty5.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 Decompressor newContentDecoder(CharSequence contentEncoding) throws Exception

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

Parameters
contentEncoding:CharSequence

the value of the "Content-Encoding" header

Returns:Decompressor

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