Class HttpObjectEncoder<H extends HttpMessage>

  • All Implemented Interfaces:
    io.netty5.channel.ChannelHandler
    Direct Known Subclasses:
    HttpRequestEncoder, HttpResponseEncoder, RtspEncoder

    public abstract class HttpObjectEncoder<H extends HttpMessage>
    extends io.netty5.handler.codec.MessageToMessageEncoder<Object>
    Encodes an HttpMessage or an HttpContent into a Buffer.

    Extensibility

    Please note that this encoder is designed to be extended to implement a protocol derived from HTTP, such as RTSP and ICAP. To implement the encoder of such a derived protocol, extend this class and implement all abstract methods properly.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean acceptOutboundMessage​(Object msg)  
      protected io.netty5.buffer.api.Buffer crlfBuffer​(io.netty5.buffer.api.BufferAllocator allocator)  
      protected void encodeAndClose​(io.netty5.channel.ChannelHandlerContext ctx, Object msg, List<Object> out)  
      protected void encodeHeaders​(HttpHeaders headers, io.netty5.buffer.api.Buffer buf)
      Encode the HttpHeaders into a Buffer.
      protected abstract void encodeInitialLine​(io.netty5.buffer.api.Buffer buf, H message)  
      protected boolean isContentAlwaysEmpty​(H msg)
      Determine whether a message has a content or not.
      protected void sanitizeHeadersBeforeEncode​(H msg, boolean isAlwaysEmpty)
      Allows to sanitize headers of the message before encoding these.
      protected io.netty5.buffer.api.Buffer zeroCrlfCrlfBuffer​(io.netty5.buffer.api.BufferAllocator allocator)  
      • Methods inherited from class io.netty5.handler.codec.MessageToMessageEncoder

        encode, write
      • Methods inherited from interface io.netty5.channel.ChannelHandler

        bind, channelActive, channelExceptionCaught, channelInactive, channelInboundEvent, channelRead, channelReadComplete, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown
    • Constructor Detail

      • HttpObjectEncoder

        public HttpObjectEncoder()
    • Method Detail

      • encodeAndClose

        protected void encodeAndClose​(io.netty5.channel.ChannelHandlerContext ctx,
                                      Object msg,
                                      List<Object> out)
                               throws Exception
        Overrides:
        encodeAndClose in class io.netty5.handler.codec.MessageToMessageEncoder<Object>
        Throws:
        Exception
      • encodeHeaders

        protected void encodeHeaders​(HttpHeaders headers,
                                     io.netty5.buffer.api.Buffer buf)
        Encode the HttpHeaders into a Buffer.
      • sanitizeHeadersBeforeEncode

        protected void sanitizeHeadersBeforeEncode​(H msg,
                                                   boolean isAlwaysEmpty)
        Allows to sanitize headers of the message before encoding these.
      • isContentAlwaysEmpty

        protected boolean isContentAlwaysEmpty​(H msg)
        Determine whether a message has a content or not. Some message may have headers indicating a content without having an actual content, e.g the response to an HEAD or CONNECT request.
        Parameters:
        msg - the message to test
        Returns:
        true to signal the message has no content
      • acceptOutboundMessage

        public boolean acceptOutboundMessage​(Object msg)
                                      throws Exception
        Overrides:
        acceptOutboundMessage in class io.netty5.handler.codec.MessageToMessageEncoder<Object>
        Throws:
        Exception
      • encodeInitialLine

        protected abstract void encodeInitialLine​(io.netty5.buffer.api.Buffer buf,
                                                  H message)
                                           throws Exception
        Throws:
        Exception
      • crlfBuffer

        protected io.netty5.buffer.api.Buffer crlfBuffer​(io.netty5.buffer.api.BufferAllocator allocator)
      • zeroCrlfCrlfBuffer

        protected io.netty5.buffer.api.Buffer zeroCrlfCrlfBuffer​(io.netty5.buffer.api.BufferAllocator allocator)