Class HttpContentDecoder

  • All Implemented Interfaces:
    io.netty5.channel.ChannelHandler
    Direct Known Subclasses:
    HttpContentDecompressor

    public abstract class HttpContentDecoder
    extends io.netty5.handler.codec.MessageToMessageDecoder<HttpObject>
    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(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 Buffers into HTTP requests.

    • Nested Class Summary

      • Nested classes/interfaces inherited from interface io.netty5.channel.ChannelHandler

        io.netty5.channel.ChannelHandler.Sharable
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected io.netty5.channel.ChannelHandlerContext ctx  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void channelInactive​(io.netty5.channel.ChannelHandlerContext ctx)  
      void channelReadComplete​(io.netty5.channel.ChannelHandlerContext ctx)  
      protected void decode​(io.netty5.channel.ChannelHandlerContext ctx, HttpObject msg)  
      protected String getTargetContentEncoding​(String contentEncoding)
      Returns the expected content encoding of the decoded content.
      void handlerAdded​(io.netty5.channel.ChannelHandlerContext ctx)  
      void handlerRemoved​(io.netty5.channel.ChannelHandlerContext ctx)  
      protected abstract io.netty5.handler.codec.compression.Decompressor newContentDecoder​(String contentEncoding)
      Returns a new Decompressor that decodes the HTTP message content encoded in the specified contentEncoding.
      • Methods inherited from class io.netty5.handler.codec.MessageToMessageDecoder

        acceptInboundMessage, channelRead
      • Methods inherited from class io.netty5.channel.ChannelHandlerAdapter

        ensureNotSharable, isSharable
      • Methods inherited from interface io.netty5.channel.ChannelHandler

        bind, channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, read, register, userEventTriggered, write
    • Field Detail

      • ctx

        protected io.netty5.channel.ChannelHandlerContext ctx
    • Constructor Detail

      • HttpContentDecoder

        public HttpContentDecoder()
    • Method Detail

      • decode

        protected void decode​(io.netty5.channel.ChannelHandlerContext ctx,
                              HttpObject msg)
                       throws Exception
        Specified by:
        decode in class io.netty5.handler.codec.MessageToMessageDecoder<HttpObject>
        Throws:
        Exception
      • channelReadComplete

        public void channelReadComplete​(io.netty5.channel.ChannelHandlerContext ctx)
                                 throws Exception
        Throws:
        Exception
      • newContentDecoder

        protected abstract io.netty5.handler.codec.compression.Decompressor newContentDecoder​(String contentEncoding)
                                                                                       throws Exception
        Returns a new Decompressor 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​(io.netty5.channel.ChannelHandlerContext ctx)
                            throws Exception
        Throws:
        Exception
      • channelInactive

        public void channelInactive​(io.netty5.channel.ChannelHandlerContext ctx)
                             throws Exception
        Throws:
        Exception
      • handlerAdded

        public void handlerAdded​(io.netty5.channel.ChannelHandlerContext ctx)
                          throws Exception
        Throws:
        Exception