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
  • HttpServerUpgradeHandler

This view

  • Original page
  • New address

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

Class HttpServerUpgradeHandler

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.handler.codec.MessageToMessageDecoder<HttpObject>
io.netty.handler.codec.MessageAggregator<HttpObject, HttpMessage, HttpContent, FullHttpMessage>
io.netty.handler.codec.http.HttpObjectAggregator
io.netty.handler.codec.http.HttpServerUpgradeHandler
All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler

public class HttpServerUpgradeHandler extends HttpObjectAggregator
A server-side handler that receives HTTP requests and optionally performs a protocol switch if the requested protocol is supported. Once an upgrade is performed, this handler removes itself from the pipeline.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    HttpServerUpgradeHandler.SourceCodec
    The source codec that is used in the pipeline initially.
    static interface 
    HttpServerUpgradeHandler.UpgradeCodec
    A codec that the source can be upgraded to.
    static interface 
    HttpServerUpgradeHandler.UpgradeCodecFactory
    Creates a new HttpServerUpgradeHandler.UpgradeCodec for the requested protocol name.
    static final class 
    HttpServerUpgradeHandler.UpgradeEvent
    User event that is fired to notify about the completion of an HTTP upgrade to another protocol.

    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.
  • Constructor Summary

    Constructors
    Constructor
    Description
    HttpServerUpgradeHandler(HttpServerUpgradeHandler.SourceCodec sourceCodec, HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory)
    Constructs the upgrader with the supported codecs.
    HttpServerUpgradeHandler(HttpServerUpgradeHandler.SourceCodec sourceCodec, HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory, int maxContentLength)
    Constructs the upgrader with the supported codecs.
    HttpServerUpgradeHandler(HttpServerUpgradeHandler.SourceCodec sourceCodec, HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory, int maxContentLength, boolean validateHeaders)
    Constructs the upgrader with the supported codecs.
    HttpServerUpgradeHandler(HttpServerUpgradeHandler.SourceCodec sourceCodec, HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory, int maxContentLength, HttpHeadersFactory headersFactory, HttpHeadersFactory trailersFactory)
    Constructs the upgrader with the supported codecs.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected FullHttpMessage
    beginAggregation(HttpMessage start, ByteBuf content)
    Creates a new aggregated message from the specified start message and the specified content.
    protected void
    decode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out)
    Decode from one message to an other.
    protected boolean
    shouldHandleUpgradeRequest(HttpRequest req)
    Determines whether the specified upgrade HttpRequest should be handled by this handler or not.

    Methods inherited from class HttpObjectAggregator

    aggregate, closeAfterContinueResponse, finishAggregation, handleOversizedMessage, ignoreContentAfterContinueResponse, isAggregated, isContentLengthInvalid, isContentMessage, isLastContentMessage, isStartMessage, newContinueResponse
    Modifier and Type
    Method
    Description
    protected void
    aggregate(FullHttpMessage aggregated, HttpContent content)
    Transfers the information provided by the specified content message to the specified aggregated message.
    protected boolean
    closeAfterContinueResponse(Object msg)
    Determine if the channel should be closed after the result of MessageAggregator.newContinueResponse(Object, int, ChannelPipeline) is written.
    protected void
    finishAggregation(FullHttpMessage aggregated)
    Invoked when the specified aggregated message is about to be passed to the next handler in the pipeline.
    protected void
    handleOversizedMessage(ChannelHandlerContext ctx, HttpMessage oversized)
    Invoked when an incoming request exceeds the maximum content length.
    protected boolean
    ignoreContentAfterContinueResponse(Object msg)
    Determine if all objects for the current request/response should be ignored or not.
    protected boolean
    isAggregated(HttpObject msg)
    Returns true if and only if the specified message is already aggregated.
    protected boolean
    isContentLengthInvalid(HttpMessage start, int maxContentLength)
    Determine if the message start's content length is known, and if it greater than maxContentLength.
    protected boolean
    isContentMessage(HttpObject msg)
    Returns true if and only if the specified message is a content message.
    protected boolean
    isLastContentMessage(HttpContent msg)
    Returns true if and only if the specified message is the last content message.
    protected boolean
    isStartMessage(HttpObject msg)
    Returns true if and only if the specified message is a start message.
    protected Object
    newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline)
    Returns the 'continue response' for the specified start message if necessary.

    Methods inherited from class MessageAggregator

    acceptInboundMessage, channelInactive, channelReadComplete, ctx, handlerAdded, handlerRemoved, isHandlingOversizedMessage, maxContentLength, maxCumulationBufferComponents, releaseCurrentMessage, setMaxCumulationBufferComponents
    Modifier and Type
    Method
    Description
    boolean
    acceptInboundMessage(Object msg)
    Returns true if the given message should be handled.
    void
    channelInactive(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelInactive() 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.
    protected final ChannelHandlerContext
    ctx()
     
    void
    handlerAdded(ChannelHandlerContext ctx)
    Do nothing by default, sub-classes may override this method.
    void
    handlerRemoved(ChannelHandlerContext ctx)
    Do nothing by default, sub-classes may override this method.
    final boolean
    isHandlingOversizedMessage()
    Deprecated.
    This method will be removed in future releases.
    final int
    maxContentLength()
    Returns the maximum allowed length of the aggregated message in bytes.
    final int
    maxCumulationBufferComponents()
    Returns the maximum number of components in the cumulation buffer.
    protected final void
    releaseCurrentMessage()
     
    final void
    setMaxCumulationBufferComponents(int maxCumulationBufferComponents)
    Sets the maximum number of components in the cumulation buffer.

    Methods inherited from class MessageToMessageDecoder

    channelRead
    Modifier and Type
    Method
    Description
    void
    channelRead(ChannelHandlerContext ctx, Object msg)
    Calls ChannelHandlerContext.fireChannelRead(Object) to forward to the next ChannelInboundHandler 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, isSharable
    Modifier and Type
    Method
    Description
    protected void
    ensureNotSharable()
    Throws IllegalStateException if ChannelHandlerAdapter.isSharable() returns true
    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
  • Constructor Details

    • HttpServerUpgradeHandler

      public HttpServerUpgradeHandler(HttpServerUpgradeHandler.SourceCodec sourceCodec, HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory)
      Constructs the upgrader with the supported codecs.

      The handler instantiated by this constructor will reject an upgrade request with non-empty content. It should not be a concern because an upgrade request is most likely a GET request. If you have a client that sends a non-GET upgrade request, please consider using HttpServerUpgradeHandler(SourceCodec, UpgradeCodecFactory, int) to specify the maximum length of the content of an upgrade request.

      Parameters:
      sourceCodec - the codec that is being used initially
      upgradeCodecFactory - the factory that creates a new upgrade codec for one of the requested upgrade protocols
    • HttpServerUpgradeHandler

      public HttpServerUpgradeHandler(HttpServerUpgradeHandler.SourceCodec sourceCodec, HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory, int maxContentLength)
      Constructs the upgrader with the supported codecs.
      Parameters:
      sourceCodec - the codec that is being used initially
      upgradeCodecFactory - the factory that creates a new upgrade codec for one of the requested upgrade protocols
      maxContentLength - the maximum length of the content of an upgrade request
    • HttpServerUpgradeHandler

      public HttpServerUpgradeHandler(HttpServerUpgradeHandler.SourceCodec sourceCodec, HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory, int maxContentLength, boolean validateHeaders)
      Constructs the upgrader with the supported codecs.
      Parameters:
      sourceCodec - the codec that is being used initially
      upgradeCodecFactory - the factory that creates a new upgrade codec for one of the requested upgrade protocols
      maxContentLength - the maximum length of the content of an upgrade request
      validateHeaders - validate the header names and values of the upgrade response.
    • HttpServerUpgradeHandler

      public HttpServerUpgradeHandler(HttpServerUpgradeHandler.SourceCodec sourceCodec, HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory, int maxContentLength, HttpHeadersFactory headersFactory, HttpHeadersFactory trailersFactory)
      Constructs the upgrader with the supported codecs.
      Parameters:
      sourceCodec - the codec that is being used initially
      upgradeCodecFactory - the factory that creates a new upgrade codec for one of the requested upgrade protocols
      maxContentLength - the maximum length of the content of an upgrade request
      headersFactory - The HttpHeadersFactory to use for headers. The recommended default factory is DefaultHttpHeadersFactory.headersFactory().
      trailersFactory - The HttpHeadersFactory to use for trailers. The recommended default factory is DefaultHttpHeadersFactory.trailersFactory().
  • Method Details

    • decode

      protected void decode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out) throws Exception
      Description copied from class: MessageToMessageDecoder
      Decode from one message to an other. This method will be called for each written message that can be handled by this decoder.
      Overrides:
      decode in class MessageAggregator<HttpObject, HttpMessage, HttpContent, FullHttpMessage>
      Parameters:
      ctx - the ChannelHandlerContext which this MessageToMessageDecoder belongs to
      msg - the message to decode to an other one
      out - the List to which decoded messages should be added
      Throws:
      Exception - is thrown if an error occurs
    • beginAggregation

      protected FullHttpMessage beginAggregation(HttpMessage start, ByteBuf content) throws Exception
      Description copied from class: MessageAggregator
      Creates a new aggregated message from the specified start message and the specified content. If the start message implements ByteBufHolder, its content is appended to the specified content. This aggregator will continue to append the received content to the specified content.
      Overrides:
      beginAggregation in class HttpObjectAggregator
      Throws:
      Exception
    • shouldHandleUpgradeRequest

      protected boolean shouldHandleUpgradeRequest(HttpRequest req)
      Determines whether the specified upgrade HttpRequest should be handled by this handler or not. This method will be invoked only when the request contains an Upgrade header. It always returns true by default, which means any request with an Upgrade header will be handled. You can override this method to ignore certain Upgrade headers, for example:
      @Override
      protected boolean isUpgradeRequest(HttpRequest req) {
        // Do not handle WebSocket upgrades.
        return !req.headers().contains(HttpHeaderNames.UPGRADE, "websocket", false);
      }
      
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.