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 Detail

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

      • isUpgradeRequest

        private static boolean isUpgradeRequest​(HttpObject msg)
        Determines whether or not the message is an HTTP upgrade request.
      • 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 static 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.