Exemplo n.º 1
0
        private static void TestUpgrade(Http2ConnectionHandler handler, Http2MultiplexHandler multiplexer)
        {
            IFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.Http11, HttpMethod.Options, "*");

            EmbeddedChannel        channel = new EmbeddedChannel(new ChannelHandlerAdapter());
            IChannelHandlerContext ctx     = channel.Pipeline.FirstContext();

            Http2ClientUpgradeCodec codec;

            if (multiplexer == null)
            {
                codec = new Http2ClientUpgradeCodec("connectionHandler", handler);
            }
            else
            {
                codec = new Http2ClientUpgradeCodec("connectionHandler", handler, multiplexer);
            }

            codec.SetUpgradeHeaders(ctx, request);
            // Flush the channel to ensure we write out all buffered data
            channel.Flush();

            codec.UpgradeTo(ctx, null);
            Assert.NotNull(channel.Pipeline.Get("connectionHandler"));

            if (multiplexer != null)
            {
                Assert.NotNull(channel.Pipeline.Get <Http2MultiplexHandler>());
            }

            Assert.True(channel.FinishAndReleaseAll());
        }
        /// <summary>
        /// Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.
        /// </summary>
        /// <param name="ch"></param>
        void ConfigureClearText(IChannel ch)
        {
            HttpClientCodec          sourceCodec    = new HttpClientCodec();
            Http2ClientUpgradeCodec  upgradeCodec   = new Http2ClientUpgradeCodec(_connectionHandler);
            HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, 65536);

            ch.Pipeline.AddLast(sourceCodec,
                                upgradeHandler,
                                new UpgradeRequestHandler(this),
                                new UserEventLogger());
        }