Class 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.
  • Constructor Details

  • 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);
      }