- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.handler.codec.MessageToMessageDecoder<HttpObject>
-
- io.netty5.handler.codec.http.HttpContentDecoder
-
- All Implemented Interfaces:
ChannelHandler
- Direct Known Subclasses:
HttpContentDecompressor
public abstract class HttpContentDecoder extends MessageToMessageDecoder<HttpObject>
Decodes the content of the receivedHttpRequest
andHttpContent
. The original content is replaced with the new content decoded by theDecompressor
, 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
convertsBuffer
s into HTTP requests.
-
-
Field Summary
Fields Modifier and Type Field Description protected 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(ChannelHandlerContext ctx)
TheChannel
of theChannelHandlerContext
was registered is now inactive and reached its end of lifetime.void
channelReadComplete(ChannelHandlerContext ctx)
Invoked when the last message read by the current read operation has been consumed byChannelHandler.channelRead(ChannelHandlerContext, Object)
.protected void
decodeAndClose(ChannelHandlerContext ctx, HttpObject msg)
Decode from one message to another.protected String
getTargetContentEncoding(String contentEncoding)
Returns the expected content encoding of the decoded content.void
handlerAdded(ChannelHandlerContext ctx)
Gets called after theChannelHandler
was added to the actual context and it's ready to handle events.void
handlerRemoved(ChannelHandlerContext ctx)
Gets called after theChannelHandler
was removed from the actual context and it doesn't handle events anymore.protected abstract Decompressor
newContentDecoder(String contentEncoding)
Returns a newDecompressor
that decodes the HTTP message content encoded in the specified contentEncoding.-
Methods inherited from class io.netty5.handler.codec.MessageToMessageDecoder
acceptInboundMessage, channelRead, decode
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelActive, channelExceptionCaught, channelInboundEvent, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
Field Detail
-
ctx
protected ChannelHandlerContext ctx
-
-
Method Detail
-
decodeAndClose
protected void decodeAndClose(ChannelHandlerContext ctx, HttpObject msg) throws Exception
Description copied from class:MessageToMessageDecoder
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
MessageToMessageDecoder.decodeAndClose(ChannelHandlerContext, Object)
method.- Overrides:
decodeAndClose
in classMessageToMessageDecoder<HttpObject>
- Parameters:
ctx
- theChannelHandlerContext
which thisMessageToMessageDecoder
belongs tomsg
- the message to decode to another one- Throws:
Exception
- is thrown if an error occurs
-
channelReadComplete
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
Invoked when the last message read by the current read operation has been consumed byChannelHandler.channelRead(ChannelHandlerContext, Object)
. IfChannelOption.AUTO_READ
is off, no further attempt to read an inbound data from the currentChannel
will be made untilChannelHandlerContext.read()
is called.- Throws:
Exception
-
newContentDecoder
protected abstract Decompressor newContentDecoder(String contentEncoding) throws Exception
Returns a newDecompressor
that decodes the HTTP message content encoded in the specified contentEncoding.- Parameters:
contentEncoding
- the value of the"Content-Encoding"
header- Returns:
- a new
Decompressor
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(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
Gets called after theChannelHandler
was removed from the actual context and it doesn't handle events anymore.- Throws:
Exception
-
channelInactive
public void channelInactive(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
TheChannel
of theChannelHandlerContext
was registered is now inactive and reached its end of lifetime.- Throws:
Exception
-
handlerAdded
public void handlerAdded(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
Gets called after theChannelHandler
was added to the actual context and it's ready to handle events.- Throws:
Exception
-
-