Exemplo n.º 1
0
        public async Task Reset_CompleteAsyncDuringRequestBody_Resets()
        {
            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, GetPostHeaders("/Reset_CompleteAsyncDuringRequestBody_Resets"), endStream: false);
                await h2Connection.SendDataAsync(1, new byte[10], endStream: false);

                await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
                {
                    Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
                });

                var dataFrame = await h2Connection.ReceiveFrameAsync();

                Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: true, length: 0);

                var resetFrame = await h2Connection.ReceiveFrameAsync();
                Http2Utilities.VerifyResetFrame(resetFrame, expectedStreamId: 1, expectedErrorCode: Http2ErrorCode.NO_ERROR);

                h2Connection.Logger.LogInformation("Connection stopped.");
            })
            .Build().RunAsync();
        }
Exemplo n.º 2
0
        public async Task Reset_DuringResponseBody_Resets()
        {
            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("/Reset_DuringResponseBody_Resets"), endStream: true);

                // This is currently flaky, can either receive header or reset at this point
                var headerOrResetFrame = await h2Connection.ReceiveFrameAsync();
                Assert.True(headerOrResetFrame.Type == Http2FrameType.HEADERS || headerOrResetFrame.Type == Http2FrameType.RST_STREAM);

                if (headerOrResetFrame.Type == Http2FrameType.HEADERS)
                {
                    var dataFrame = await h2Connection.ReceiveFrameAsync();
                    Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: false, length: 11);

                    var resetFrame = await h2Connection.ReceiveFrameAsync();
                    Http2Utilities.VerifyResetFrame(resetFrame, expectedStreamId: 1, expectedErrorCode: (Http2ErrorCode)1111);
                }
                else
                {
                    Http2Utilities.VerifyResetFrame(headerOrResetFrame, expectedStreamId: 1, expectedErrorCode: (Http2ErrorCode)1111);
                }

                h2Connection.Logger.LogInformation("Connection stopped.");
            })
            .Build().RunAsync();
        }
Exemplo n.º 3
0
        public async Task AppException_AfterHeaders_ResetInternalError()
        {
            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("/AppException_AfterHeaders_ResetInternalError"), endStream: true);

                await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
                {
                    Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
                });

                var frame = await h2Connection.ReceiveFrameAsync();
                if (Environment.OSVersion.Version >= Win10_Regressed_DataFrame)
                {
                    // TODO: Remove when the regression is fixed.
                    // https://github.com/dotnet/aspnetcore/issues/23164#issuecomment-652646163
                    Http2Utilities.VerifyDataFrame(frame, 1, endOfStream: false, length: 0);

                    frame = await h2Connection.ReceiveFrameAsync();
                }
                Http2Utilities.VerifyResetFrame(frame, expectedStreamId: 1, Http2ErrorCode.INTERNAL_ERROR);

                h2Connection.Logger.LogInformation("Connection stopped.");
            })
            .Build().RunAsync();
        }
Exemplo n.º 4
0
        public async Task Reset_AfterResponseHeaders_Resets()
        {
            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("/Reset_AfterResponseHeaders_Resets"), endStream: true);

                // Any app errors?
                var client   = CreateClient();
                var response = await client.GetAsync(Fixture.Client.BaseAddress + "/Reset_AfterResponseHeaders_Resets_Complete");
                Assert.True(response.IsSuccessStatusCode);

                await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
                {
                    Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
                });

                var resetFrame = await h2Connection.ReceiveFrameAsync();
                Http2Utilities.VerifyResetFrame(resetFrame, expectedStreamId: 1, expectedErrorCode: (Http2ErrorCode)1111);

                h2Connection.Logger.LogInformation("Connection stopped.");
            })
            .Build().RunAsync();
        }
Exemplo n.º 5
0
        public async Task Reset_CompleteAsyncDuringRequestBody_Resets()
        {
            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, Http2Utilities.PostRequestHeaders, endStream: false);
                await h2Connection.SendDataAsync(1, new byte[10], endStream: false);

                await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
                {
                    Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
                });

                var dataFrame = await h2Connection.ReceiveFrameAsync();
                if (Environment.OSVersion.Version >= Win10_Regressed_DataFrame)
                {
                    // TODO: Remove when the regression is fixed.
                    // https://github.com/dotnet/aspnetcore/issues/23164#issuecomment-652646163
                    Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: false, length: 0);

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

                var resetFrame = await h2Connection.ReceiveFrameAsync();
                Http2Utilities.VerifyResetFrame(resetFrame, expectedStreamId: 1, expectedErrorCode: Http2ErrorCode.NO_ERROR);

                h2Connection.Logger.LogInformation("Connection stopped.");
            })
            .Build().RunAsync();
        }
Exemplo n.º 6
0
        public async Task Reset_AfterResponseHeaders_Resets()
        {
            var deploymentParameters = GetHttpsDeploymentParameters();
            var deploymentResult     = await DeployAsync(deploymentParameters);

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

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

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

                // Any app errors?
                var client   = CreateClient();
                var response = await client.GetAsync(deploymentResult.ApplicationBaseUri + "/Reset_AfterResponseHeaders_Resets_Complete");
                Assert.True(response.IsSuccessStatusCode);

                await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
                {
                    Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
                });

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

                var resetFrame = await h2Connection.ReceiveFrameAsync();
                Http2Utilities.VerifyResetFrame(resetFrame, expectedStreamId: 1, expectedErrorCode: (Http2ErrorCode)1111);

                h2Connection.Logger.LogInformation("Connection stopped.");
            })
            .Build().RunAsync();
        }
Exemplo n.º 7
0
        public async Task Reset_DuringRequestBody_Resets()
        {
            var deploymentParameters = GetHttpsDeploymentParameters();
            var deploymentResult     = await DeployAsync(deploymentParameters);

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

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

                await h2Connection.StartStreamAsync(1, GetPostHeaders("/Reset_DuringRequestBody_Resets"), endStream: false);
                await h2Connection.SendDataAsync(1, new byte[10], endStream: false);

                // Any app errors?
                //Assert.Equal(0, await appResult.Task.DefaultTimeout());

                var resetFrame = await h2Connection.ReceiveFrameAsync();
                Http2Utilities.VerifyResetFrame(resetFrame, expectedStreamId: 1, expectedErrorCode: (Http2ErrorCode)1111);

                h2Connection.Logger.LogInformation("Connection stopped.");
            })
            .Build().RunAsync();
        }
Exemplo n.º 8
0
        public async Task AppException_AfterHeaders_ResetInternalError()
        {
            using var server = Utilities.CreateDynamicHttpsServer(out var address, async httpContext =>
            {
                await httpContext.Response.Body.FlushAsync();
                throw new Exception("Application exception");
            });

            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);

                await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
                {
                    Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
                });

                var frame = await h2Connection.ReceiveFrameAsync();
                Http2Utilities.VerifyResetFrame(frame, expectedStreamId: 1, Http2ErrorCode.INTERNAL_ERROR);

                h2Connection.Logger.LogInformation("Connection stopped.");
            })
            .Build().RunAsync();
        }
Exemplo n.º 9
0
        public async Task AppException_AfterHeaders_PriorOSVersions_ResetCancel()
        {
            var deploymentParameters = GetHttpsDeploymentParameters();
            var deploymentResult     = await DeployAsync(deploymentParameters);

            await new HostBuilder()
            .UseHttp2Cat(deploymentResult.ApplicationBaseUri + "AppException_AfterHeaders_PriorOSVersions_ResetCancel", async h2Connection =>
            {
                await h2Connection.InitializeConnectionAsync();

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

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

                await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
                {
                    Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
                });

                var resetFrame = await h2Connection.ReceiveFrameAsync();
                Http2Utilities.VerifyResetFrame(resetFrame, expectedStreamId: 1, Http2ErrorCode.CANCEL);

                h2Connection.Logger.LogInformation("Connection stopped.");
            })
            .Build().RunAsync();
        }
Exemplo n.º 10
0
        public async Task Reset_CompleteAsyncDurringRequestBody_Resets()
        {
            var appResult = new TaskCompletionSource <int>(TaskCreationOptions.RunContinuationsAsynchronously);

            using var server = Utilities.CreateDynamicHttpsServer(out var address, async httpContext =>
            {
                try
                {
                    Assert.Equal("HTTP/2", httpContext.Request.Protocol);
                    var feature = httpContext.Features.Get <IHttpResetFeature>();
                    Assert.NotNull(feature);

                    var read = await httpContext.Request.Body.ReadAsync(new byte[10], 0, 10);
                    Assert.Equal(10, read);

                    var readTask = httpContext.Request.Body.ReadAsync(new byte[10], 0, 10);
                    await httpContext.Response.CompleteAsync();
                    feature.Reset((int)Http2ErrorCode.NO_ERROR); // GRPC does this
                    await Assert.ThrowsAsync <IOException>(() => readTask);

                    appResult.SetResult(0);
                }
                catch (Exception ex)
                {
                    appResult.SetException(ex);
                }
            });

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

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

                await h2Connection.StartStreamAsync(1, Http2Utilities.PostRequestHeaders, endStream: false);
                await h2Connection.SendDataAsync(1, new byte[10], endStream: false);

                // Any app errors?
                Assert.Equal(0, await appResult.Task.DefaultTimeout());

                await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
                {
                    Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
                });

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

                var resetFrame = await h2Connection.ReceiveFrameAsync();
                Http2Utilities.VerifyResetFrame(resetFrame, expectedStreamId: 1, expectedErrorCode: Http2ErrorCode.NO_ERROR);

                h2Connection.Logger.LogInformation("Connection stopped.");
            })
            .Build().RunAsync();
        }
Exemplo n.º 11
0
        public async Task Reset_DurringResponseBody_Resets()
        {
            var appResult = new TaskCompletionSource <int>(TaskCreationOptions.RunContinuationsAsynchronously);

            using var server = Utilities.CreateDynamicHttpsServer(out var address, async httpContext =>
            {
                try
                {
                    Assert.Equal("HTTP/2", httpContext.Request.Protocol);
                    var feature = httpContext.Features.Get <IHttpResetFeature>();
                    Assert.NotNull(feature);
                    await httpContext.Response.WriteAsync("Hello World");
                    feature.Reset(1111); // Custom
                    appResult.SetResult(0);
                }
                catch (Exception ex)
                {
                    appResult.SetException(ex);
                }
            });

            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);

                // Any app errors?
                Assert.Equal(0, await appResult.Task.DefaultTimeout());

                await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
                {
                    Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
                });

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

                var resetFrame = await h2Connection.ReceiveFrameAsync();
                Http2Utilities.VerifyResetFrame(resetFrame, expectedStreamId: 1, expectedErrorCode: (Http2ErrorCode)1111);

                h2Connection.Logger.LogInformation("Connection stopped.");
            })
            .Build().RunAsync();
        }
Exemplo n.º 12
0
        public async Task Reset_BeforeRequestBody_Resets()
        {
            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, GetPostHeaders("/Reset_BeforeRequestBody_Resets"), endStream: false);

                // Any app errors?
                //Assert.Equal(0, await appResult.Task.DefaultTimeout());

                var resetFrame = await h2Connection.ReceiveFrameAsync();
                Http2Utilities.VerifyResetFrame(resetFrame, expectedStreamId: 1, expectedErrorCode: (Http2ErrorCode)1111);

                h2Connection.Logger.LogInformation("Connection stopped.");
            })
            .Build().RunAsync();
        }
Exemplo n.º 13
0
        public async Task AppException_AfterHeaders_ResetInternalError()
        {
            using var server = Utilities.CreateDynamicHttpsServer(out var address, async httpContext =>
            {
                await httpContext.Response.Body.FlushAsync();
                throw new Exception("Application exception");
            });

            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);

                await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
                {
                    Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
                });

                var frame = await h2Connection.ReceiveFrameAsync();
                if (Environment.OSVersion.Version >= Win10_Regressed_DataFrame)
                {
                    // TODO: Remove when the regression is fixed.
                    // https://github.com/dotnet/aspnetcore/issues/23164#issuecomment-652646163
                    Http2Utilities.VerifyDataFrame(frame, 1, endOfStream: false, length: 0);

                    frame = await h2Connection.ReceiveFrameAsync();
                }
                Http2Utilities.VerifyResetFrame(frame, expectedStreamId: 1, Http2ErrorCode.INTERNAL_ERROR);

                h2Connection.Logger.LogInformation("Connection stopped.");
            })
            .Build().RunAsync();
        }
Exemplo n.º 14
0
        public async Task AppException_AfterHeaders_ResetInternalError()
        {
            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("/AppException_AfterHeaders_ResetInternalError"), endStream: true);

                await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
                {
                    Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
                });

                var frame = await h2Connection.ReceiveFrameAsync();

                Http2Utilities.VerifyResetFrame(frame, expectedStreamId: 1, Http2ErrorCode.INTERNAL_ERROR);

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