From b9733f461862cff5da17df08af208c1d3e8fc1a9 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 5 Apr 2021 14:48:10 -0700 Subject: Still send 100 Continue with null MinRequestBodyDataRate (#31543) --- .../Kestrel/Core/src/Internal/Http/MessageBody.cs | 10 +++--- .../test/InMemory.FunctionalTests/RequestTests.cs | 36 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/Servers/Kestrel/Core/src/Internal/Http/MessageBody.cs b/src/Servers/Kestrel/Core/src/Internal/Http/MessageBody.cs index e5001df5dc..fd1e1376c0 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Http/MessageBody.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Http/MessageBody.cs @@ -181,13 +181,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected ValueTask StartTimingReadAsync(ValueTask readAwaitable, CancellationToken cancellationToken) { - - if (!readAwaitable.IsCompleted && _timingEnabled) + if (!readAwaitable.IsCompleted) { TryProduceContinue(); - _backpressure = true; - _context.TimeoutControl.StartTimingRead(); + if (_timingEnabled) + { + _backpressure = true; + _context.TimeoutControl.StartTimingRead(); + } } return readAwaitable; diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestTests.cs index f5bafda166..431327f0ca 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestTests.cs @@ -846,6 +846,42 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests } } + [Fact] + public async Task Expect100ContinueHonoredWhenMinRequestBodyDataRateIsDisabled() + { + var testContext = new TestServiceContext(LoggerFactory); + + // This may seem unrelated, but this is a regression test for + // https://github.com/dotnet/aspnetcore/issues/30449 + testContext.ServerOptions.Limits.MinRequestBodyDataRate = null; + + await using (var server = new TestServer(TestApp.EchoAppChunked, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Expect: 100-continue", + "Connection: close", + "Content-Length: 11", + "\r\n"); + await connection.Receive( + "HTTP/1.1 100 Continue", + "", + ""); + await connection.Send("Hello World"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 11", + "", + "Hello World"); + } + } + } + [Fact] public async Task ZeroContentLengthAssumedOnNonKeepAliveRequestsWithoutContentLengthOrTransferEncodingHeader() { -- cgit v1.2.3