Class HttpObjectEncoder<H extends HttpMessage>

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelOutboundHandlerAdapter
io.netty.handler.codec.MessageToMessageEncoder<Object>
io.netty.handler.codec.http.HttpObjectEncoder<H>
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelOutboundHandler
Direct Known Subclasses:
HttpRequestEncoder, HttpResponseEncoder, RtspEncoder, RtspObjectEncoder

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

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.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

    io.netty.channel.ChannelHandler.Sharable
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    protected void
    encode(io.netty.channel.ChannelHandlerContext ctx, Object msg, List<Object> out)
     
    protected static void
    encodeAscii(String s, io.netty.buffer.ByteBuf buf)
    Deprecated.
    protected void
    encodeHeaders(HttpHeaders headers, io.netty.buffer.ByteBuf buf)
    Encode the HttpHeaders into a ByteBuf.
    protected abstract void
    encodeInitialLine(io.netty.buffer.ByteBuf buf, H message)
     
    protected boolean
    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.
    void
    write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)
     

    Methods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter

    bind, close, connect, deregister, disconnect, flush, read

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.netty.channel.ChannelHandler

    exceptionCaught, handlerAdded, handlerRemoved
  • Constructor Details

    • HttpObjectEncoder

      public HttpObjectEncoder()
  • Method Details

    • write

      public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception
      Specified by:
      write in interface io.netty.channel.ChannelOutboundHandler
      Overrides:
      write in class io.netty.handler.codec.MessageToMessageEncoder<Object>
      Throws:
      Exception
    • encode

      protected void encode(io.netty.channel.ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception
      Specified by:
      encode in class io.netty.handler.codec.MessageToMessageEncoder<Object>
      Throws:
      Exception
    • encodeHeaders

      protected void encodeHeaders(HttpHeaders headers, io.netty.buffer.ByteBuf buf)
      Encode the HttpHeaders into a ByteBuf.
    • 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.netty.handler.codec.MessageToMessageEncoder<Object>
      Throws:
      Exception
    • encodeAscii

      @Deprecated protected static void encodeAscii(String s, io.netty.buffer.ByteBuf buf)
      Deprecated.
    • encodeInitialLine

      protected abstract void encodeInitialLine(io.netty.buffer.ByteBuf buf, H message) throws Exception
      Throws:
      Exception