public void UpgradesPipelineInSameMethodInvocation()
        {
            var httpServerCodec  = new HttpServerCodec();
            var factory          = new UpgradeFactory();
            var testInStackFrame = new ChannelHandler();

            var upgradeHandler = new HttpServerUpgradeHandler(httpServerCodec, factory);
            var channel        = new EmbeddedChannel(testInStackFrame, httpServerCodec, upgradeHandler);

            const string UpgradeString = "GET / HTTP/1.1\r\n" +
                                         "Host: example.com\r\n" +
                                         "Connection: Upgrade, HTTP2-Settings\r\n" +
                                         "Upgrade: nextprotocol\r\n" +
                                         "HTTP2-Settings: AAMAAABkAAQAAP__\r\n\r\n";
            IByteBuffer upgrade = Unpooled.CopiedBuffer(Encoding.ASCII.GetBytes(UpgradeString));

            Assert.False(channel.WriteInbound(upgrade));
            //Assert.Null(channel.Pipeline.Get<HttpServerCodec>());
            //Assert.NotNull(channel.Pipeline.Get("marker"));

            channel.Flush();
            Assert.Null(channel.Pipeline.Get <HttpServerCodec>());
            Assert.NotNull(channel.Pipeline.Get("marker"));

            var          upgradeMessage       = channel.ReadOutbound <IByteBuffer>();
            const string ExpectedHttpResponse = "HTTP/1.1 101 Switching Protocols\r\n" +
                                                "connection: upgrade\r\n" +
                                                "upgrade: nextprotocol\r\n\r\n";

            Assert.Equal(ExpectedHttpResponse, upgradeMessage.ToString(Encoding.ASCII));
            Assert.True(upgradeMessage.Release());
            Assert.False(channel.FinishAndReleaseAll());
        }
        void ConfigureClearText(IChannel ch)
        {
            IChannelPipeline p           = ch.Pipeline;
            HttpServerCodec  sourceCodec = new HttpServerCodec();

            p.AddLast(sourceCodec);
            p.AddLast(new HttpServerUpgradeHandler(sourceCodec, UpgradeCodecFactory));
            p.AddLast(new HttpMessageHandler(this.maxHttpContentLength));

            p.AddLast(new UserEventLogger());
        }
Exemplo n.º 3
0
        void ConfigureClearText(IChannel ch)
        {
            IChannelPipeline                   p              = ch.Pipeline;
            HttpServerCodec                    sourceCodec    = new HttpServerCodec();
            HttpServerUpgradeHandler           upgradeHandler = new HttpServerUpgradeHandler(sourceCodec, UpgradeCodecFactory);
            CleartextHttp2ServerUpgradeHandler cleartextHttp2ServerUpgradeHandler =
                new CleartextHttp2ServerUpgradeHandler(sourceCodec, upgradeHandler,
                                                       new HelloWorldHttp2HandlerBuilder().Build());

            p.AddLast(cleartextHttp2ServerUpgradeHandler);
            p.AddLast(new HttpMessageHandler(this.maxHttpContentLength));

            p.AddLast(new UserEventLogger());
        }
        /// <summary>
        /// Creates the channel handler provide cleartext HTTP/2 upgrade from HTTP
        /// upgrade or prior knowledge.
        /// </summary>
        /// <param name="httpServerCodec">the http server codec</param>
        /// <param name="httpServerUpgradeHandler">the http server upgrade handler for HTTP/2</param>
        /// <param name="http2ServerHandler">the http2 server handler, will be added into pipeline
        /// when starting HTTP/2 by prior knowledge</param>
        public CleartextHttp2ServerUpgradeHandler(HttpServerCodec httpServerCodec,
                                                  HttpServerUpgradeHandler httpServerUpgradeHandler, IChannelHandler http2ServerHandler)
        {
            if (httpServerCodec is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.httpServerCodec);
            }
            if (httpServerUpgradeHandler is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.httpServerUpgradeHandler);
            }
            if (http2ServerHandler is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.http2ServerHandler);
            }

            _httpServerCodec          = httpServerCodec;
            _httpServerUpgradeHandler = httpServerUpgradeHandler;
            _http2ServerHandler       = http2ServerHandler;
        }
Exemplo n.º 5
0
        public void UnfinishedChunkedHttpRequestIsLastFlag()
        {
            const int MaxChunkSize    = 2000;
            var       httpServerCodec = new HttpServerCodec(1000, 1000, MaxChunkSize);
            var       ch = new EmbeddedChannel(httpServerCodec);

            int totalContentLength = MaxChunkSize * 5;

            ch.WriteInbound(Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes(
                                                      "PUT /test HTTP/1.1\r\n" +
                                                      "Content-Length: " + totalContentLength + "\r\n" +
                                                      "\r\n")));

            int offeredContentLength = (int)(MaxChunkSize * 2.5);

            ch.WriteInbound(PrepareDataChunk(offeredContentLength));
            ch.Finish();

            var httpMessage = ch.ReadInbound <IHttpMessage>();

            Assert.NotNull(httpMessage);

            bool empty            = true;
            int  totalBytesPolled = 0;

            for (;;)
            {
                var httpChunk = ch.ReadInbound <IHttpContent>();
                if (httpChunk == null)
                {
                    break;
                }
                empty             = false;
                totalBytesPolled += httpChunk.Content.ReadableBytes;
                Assert.False(httpChunk is ILastHttpContent);
                httpChunk.Release();
            }

            Assert.False(empty);
            Assert.Equal(offeredContentLength, totalBytesPolled);
        }