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.
    • Method Detail

      • beginAggregation

        protected FullHttpMessage beginAggregation​(HttpMessage start,
                                                   ByteBuf content)
                                            throws java.lang.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:
        java.lang.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:
        {@code
      • upgrade

        private boolean upgrade​(ChannelHandlerContext ctx,
                                FullHttpRequest request)
        Attempts to upgrade to the protocol(s) identified by the HttpHeaderNames.UPGRADE header (if provided in the request).
        Parameters:
        ctx - the context for this handler.
        request - the HTTP request.
        Returns:
        true if the upgrade occurred, otherwise false.
      • createUpgradeResponse

        private FullHttpResponse createUpgradeResponse​(java.lang.CharSequence upgradeProtocol)
        Creates the 101 Switching Protocols response message.
      • splitHeader

        private static java.util.List<java.lang.CharSequence> splitHeader​(java.lang.CharSequence header)
        Splits a comma-separated header value. The returned set is case-insensitive and contains each part with whitespace removed.