GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Overview
  • Use
  • Tree
  • Deprecated
  • Index
  • Search
  • Help
  • io.netty.handler.codec.http
  • HttpContentEncoder

This view

  • Original page
  • New address

GeezerVison is showing netty.io — HttpContentEncoder (Netty API Reference (4.1.141.Final))

Class HttpContentEncoder

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.netty.handler.codec.MessageToMessageCodec<HttpRequest, HttpObject>
io.netty.handler.codec.http.HttpContentEncoder
All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler
Direct Known Subclasses:
HttpContentCompressor

public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpRequest, HttpObject>
Encodes the content of the outbound HttpResponse and HttpContent. The original content is replaced with the new content encoded by the EmbeddedChannel, which is created by beginEncode(HttpResponse, String). Once encoding is finished, the value of the 'Content-Encoding' header is set to the target content encoding, as returned by beginEncode(HttpResponse, String). Also, the 'Content-Length' header is updated to the length of the encoded content. If there is no supported or allowed encoding in the corresponding HttpRequest's "Accept-Encoding" header, beginEncode(HttpResponse, String) should return null so that no encoding occurs (i.e. pass-through).

Please note that this is an abstract class. You have to extend this class and implement beginEncode(HttpResponse, String) properly to make this class functional. For example, refer to the source code of HttpContentCompressor.

This handler must be placed after HttpObjectEncoder in the pipeline so that this handler can intercept HTTP responses before HttpObjectEncoder converts them into ByteBufs.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    HttpContentEncoder.Result
     

    Nested classes/interfaces inherited from interface ChannelHandler

    ChannelHandler.Sharable
    Modifier and Type
    Interface
    Description
    static @interface 
    ChannelHandler.Sharable
    Indicates that the same instance of the annotated ChannelHandler can be added to one or more ChannelPipelines multiple times without a race condition.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    DEFAULT_MAX_PIPELINE_DEPTH
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    HttpContentEncoder()
     
    HttpContentEncoder(int maxPipelineDepth)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    acceptOutboundMessage(Object msg)
    Returns true if and only if the specified message can be encoded by this codec.
    protected abstract HttpContentEncoder.Result
    beginEncode(HttpResponse httpResponse, String acceptEncoding)
    Prepare to encode the HTTP message content.
    void
    channelInactive(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelInactive() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    protected void
    decode(ChannelHandlerContext ctx, HttpRequest msg, List<Object> out)
     
    protected void
    encode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out)
     
    void
    handlerRemoved(ChannelHandlerContext ctx)
    Do nothing by default, sub-classes may override this method.

    Methods inherited from class MessageToMessageCodec

    acceptInboundMessage, channelRead, channelReadComplete, write
    Modifier and Type
    Method
    Description
    boolean
    acceptInboundMessage(Object msg)
    Returns true if and only if the specified message can be decoded by this codec.
    void
    channelRead(ChannelHandlerContext ctx, Object msg)
    Calls ChannelHandlerContext.fireChannelRead(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    channelReadComplete(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelReadComplete() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
    Calls ChannelOutboundInvoker.write(Object, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.

    Methods inherited from class ChannelDuplexHandler

    bind, close, connect, deregister, disconnect, flush, read
    Modifier and Type
    Method
    Description
    void
    bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise)
    Calls ChannelOutboundInvoker.bind(SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    close(ChannelHandlerContext ctx, ChannelPromise promise)
    Calls ChannelOutboundInvoker.close(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise)
    Calls ChannelOutboundInvoker.connect(SocketAddress, SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    deregister(ChannelHandlerContext ctx, ChannelPromise promise)
    Calls ChannelOutboundInvoker.deregister(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    disconnect(ChannelHandlerContext ctx, ChannelPromise promise)
    Calls ChannelOutboundInvoker.disconnect(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    flush(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.flush() to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    read(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.read() to forward to the next ChannelOutboundHandler in the ChannelPipeline.

    Methods inherited from class ChannelInboundHandlerAdapter

    channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
    Modifier and Type
    Method
    Description
    void
    channelActive(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelActive() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    channelRegistered(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelRegistered() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    channelUnregistered(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelUnregistered() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    channelWritabilityChanged(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelWritabilityChanged() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
    Calls ChannelHandlerContext.fireExceptionCaught(Throwable) to forward to the next ChannelHandler in the ChannelPipeline.
    void
    userEventTriggered(ChannelHandlerContext ctx, Object evt)
    Calls ChannelHandlerContext.fireUserEventTriggered(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline.

    Methods inherited from class ChannelHandlerAdapter

    ensureNotSharable, handlerAdded, isSharable
    Modifier and Type
    Method
    Description
    protected void
    ensureNotSharable()
    Throws IllegalStateException if ChannelHandlerAdapter.isSharable() returns true
    void
    handlerAdded(ChannelHandlerContext ctx)
    Do nothing by default, sub-classes may override this method.
    boolean
    isSharable()
    Return true if the implementation is ChannelHandler.Sharable and so can be added to different ChannelPipelines.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_MAX_PIPELINE_DEPTH

      public static final int DEFAULT_MAX_PIPELINE_DEPTH
      See Also:
      • Constant Field Values
  • Constructor Details

    • HttpContentEncoder

      public HttpContentEncoder()
    • HttpContentEncoder

      public HttpContentEncoder(int maxPipelineDepth)
  • Method Details

    • acceptOutboundMessage

      public boolean acceptOutboundMessage(Object msg) throws Exception
      Description copied from class: MessageToMessageCodec
      Returns true if and only if the specified message can be encoded by this codec.
      Overrides:
      acceptOutboundMessage in class MessageToMessageCodec<HttpRequest, HttpObject>
      Parameters:
      msg - the message
      Throws:
      Exception
    • decode

      protected void decode(ChannelHandlerContext ctx, HttpRequest msg, List<Object> out) throws Exception
      Specified by:
      decode in class MessageToMessageCodec<HttpRequest, HttpObject>
      Throws:
      Exception
      See Also:
      • MessageToMessageDecoder.decode(ChannelHandlerContext, Object, List)
    • encode

      protected void encode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out) throws Exception
      Specified by:
      encode in class MessageToMessageCodec<HttpRequest, HttpObject>
      Throws:
      Exception
      See Also:
      • MessageToMessageEncoder.encode(ChannelHandlerContext, Object, List)
    • beginEncode

      protected abstract HttpContentEncoder.Result beginEncode(HttpResponse httpResponse, String acceptEncoding) throws Exception
      Prepare to encode the HTTP message content.
      Parameters:
      httpResponse - the http response
      acceptEncoding - the value of the "Accept-Encoding" header
      Returns:
      the result of preparation, which is composed of the determined target content encoding and a new EmbeddedChannel that encodes the content into the target content encoding. null if acceptEncoding is unsupported or rejected and thus the content should be handled as-is (i.e. no encoding).
      Throws:
      Exception
    • handlerRemoved

      public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
      Description copied from class: ChannelHandlerAdapter
      Do nothing by default, sub-classes may override this method.
      Specified by:
      handlerRemoved in interface ChannelHandler
      Overrides:
      handlerRemoved in class ChannelHandlerAdapter
      Throws:
      Exception
    • channelInactive

      public void channelInactive(ChannelHandlerContext ctx) throws Exception
      Description copied from class: ChannelInboundHandlerAdapter
      Calls ChannelHandlerContext.fireChannelInactive() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.
      Specified by:
      channelInactive in interface ChannelInboundHandler
      Overrides:
      channelInactive in class ChannelInboundHandlerAdapter
      Throws:
      Exception
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.