Example #1
0
    public async Task RequestClose_SendsGoAway()
    {
        await new HostBuilder()
        .UseHttp2Cat(Fixture.Client.BaseAddress.AbsoluteUri, async h2Connection =>
        {
            await h2Connection.InitializeConnectionAsync();

            h2Connection.Logger.LogInformation("Initialized http2 connection. Starting stream 1.");

            await h2Connection.StartStreamAsync(1, GetHeaders("/ConnectionRequestClose"), endStream: true);

            var goAwayFrame = await h2Connection.ReceiveFrameAsync();
            Http2Utilities.VerifyGoAway(goAwayFrame, int.MaxValue, Http2ErrorCode.NO_ERROR);

            await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
            {
                // HTTP/2 filters out the connection header
                Assert.False(decodedHeaders.ContainsKey(HeaderNames.Connection));
                Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
            });

            var dataFrame = await h2Connection.ReceiveFrameAsync();
            Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: true, length: 0);

            // Http.Sys doesn't send a final GoAway unless we ignore the first one and send 200 additional streams.

            h2Connection.Logger.LogInformation("Connection stopped.");
        })
        .Build().RunAsync();
    }
Example #2
0
    public async Task ConnectionRequestClose_OSSupport_SendsGoAway()
    {
        using var server = Utilities.CreateDynamicHttpsServer(out var address, httpContext =>
        {
            httpContext.Connection.RequestClose();
            return(Task.FromResult(0));
        });

        await new HostBuilder()
        .UseHttp2Cat(address, async h2Connection =>
        {
            await h2Connection.InitializeConnectionAsync();

            h2Connection.Logger.LogInformation("Initialized http2 connection. Starting stream 1.");

            await h2Connection.StartStreamAsync(1, Http2Utilities.BrowserRequestHeaders, endStream: true);

            var goAwayFrame = await h2Connection.ReceiveFrameAsync();
            Http2Utilities.VerifyGoAway(goAwayFrame, int.MaxValue, Http2ErrorCode.NO_ERROR);

            await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
            {
                // HTTP/2 filters out the connection header
                Assert.False(decodedHeaders.ContainsKey(HeaderNames.Connection));
                Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
            });

            var dataFrame = await h2Connection.ReceiveFrameAsync();
            Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: true, length: 0);

            // Http.Sys doesn't send a final GoAway unless we ignore the first one and send 200 additional streams.

            h2Connection.Logger.LogInformation("Connection stopped.");
        })
        .Build().RunAsync();
    }
Example #3
0
    public async Task ConnectionClose_AdditionalRequests_ReceivesSecondGoAway()
    {
        using var server = Utilities.CreateDynamicHttpsServer(out var address, httpContext =>
        {
            httpContext.Response.Headers.Connection = "close";
            return(Task.FromResult(0));
        });

        await new HostBuilder()
        .UseHttp2Cat(address, async h2Connection =>
        {
            await h2Connection.InitializeConnectionAsync();

            h2Connection.Logger.LogInformation("Initialized http2 connection. Starting stream 1.");

            var streamId = 1;
            await h2Connection.StartStreamAsync(streamId, Http2Utilities.BrowserRequestHeaders, endStream: true);

            var goAwayFrame = await h2Connection.ReceiveFrameAsync();
            Http2Utilities.VerifyGoAway(goAwayFrame, int.MaxValue, Http2ErrorCode.NO_ERROR);

            await h2Connection.ReceiveHeadersAsync(streamId, decodedHeaders =>
            {
                // HTTP/2 filters out the connection header
                Assert.False(decodedHeaders.ContainsKey(HeaderNames.Connection));
                Assert.Equal("200", decodedHeaders[InternalHeaderNames.Status]);
            });

            var dataFrame = await h2Connection.ReceiveFrameAsync();
            Http2Utilities.VerifyDataFrame(dataFrame, streamId, endOfStream: true, length: 0);

            // Http.Sys doesn't send a final GoAway unless we ignore the first one and send 200 additional streams.

            for (var i = 1; i < 200; i++)
            {
                streamId = 1 + (i * 2);     // Odds.
                await h2Connection.StartStreamAsync(streamId, Http2Utilities.BrowserRequestHeaders, endStream: true);

                await h2Connection.ReceiveHeadersAsync(streamId, decodedHeaders =>
                {
                    // HTTP/2 filters out the connection header
                    Assert.False(decodedHeaders.ContainsKey(HeaderNames.Connection));
                    Assert.Equal("200", decodedHeaders[InternalHeaderNames.Status]);
                });

                dataFrame = await h2Connection.ReceiveFrameAsync();
                Http2Utilities.VerifyDataFrame(dataFrame, streamId, endOfStream: true, length: 0);
            }

            streamId = 1 + (200 * 2);     // Odds.
            await h2Connection.StartStreamAsync(streamId, Http2Utilities.BrowserRequestHeaders, endStream: true);

            // Final GoAway
            goAwayFrame = await h2Connection.ReceiveFrameAsync();
            Http2Utilities.VerifyGoAway(goAwayFrame, streamId, Http2ErrorCode.NO_ERROR);

            // Normal response
            await h2Connection.ReceiveHeadersAsync(streamId, decodedHeaders =>
            {
                // HTTP/2 filters out the connection header
                Assert.False(decodedHeaders.ContainsKey(HeaderNames.Connection));
                Assert.Equal("200", decodedHeaders[InternalHeaderNames.Status]);
            });

            dataFrame = await h2Connection.ReceiveFrameAsync();
            Http2Utilities.VerifyDataFrame(dataFrame, streamId, endOfStream: true, length: 0);

            h2Connection.Logger.LogInformation("Connection stopped.");
        })
        .Build().RunAsync();
    }