Consumes request before closing connection (#2314)
This commit is contained in:
parent
b0673337e9
commit
9341f72b8d
|
|
@ -294,6 +294,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
|||
RequestUpgrade = true;
|
||||
}
|
||||
|
||||
public override bool IsEmpty => true;
|
||||
|
||||
protected override bool Read(ReadOnlyBuffer<byte> readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined)
|
||||
{
|
||||
Copy(readableBuffer, writableBuffer);
|
||||
|
|
|
|||
|
|
@ -533,7 +533,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
|||
await ProduceEnd();
|
||||
|
||||
// ForZeroContentLength does not complete the reader nor the writer
|
||||
if (!messageBody.IsEmpty && _keepAlive)
|
||||
if (!messageBody.IsEmpty)
|
||||
{
|
||||
// Finish reading the request body in case the app did not.
|
||||
await messageBody.ConsumeAsync();
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting.Server;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
|
||||
|
|
@ -792,6 +793,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
|||
Assert.StartsWith(CoreStrings.NonNegativeNumberOrNullRequired, ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConsumesRequestWhenApplicationDoesNotConsumeIt()
|
||||
{
|
||||
var httpApplication = new DummyApplication(async context =>
|
||||
{
|
||||
var buffer = new byte[10];
|
||||
await context.Response.Body.WriteAsync(buffer, 0, 10);
|
||||
});
|
||||
var mockMessageBody = new Mock<MessageBody>(null);
|
||||
_http1Connection.NextMessageBody = mockMessageBody.Object;
|
||||
|
||||
var requestProcessingTask = _http1Connection.ProcessRequestsAsync(httpApplication);
|
||||
|
||||
var data = Encoding.ASCII.GetBytes("POST / HTTP/1.1\r\nHost:\r\nConnection: close\r\ncontent-length: 1\r\n\r\n");
|
||||
await _application.Output.WriteAsync(data);
|
||||
await requestProcessingTask.TimeoutAfter(TestConstants.DefaultTimeout);
|
||||
|
||||
mockMessageBody.Verify(body => body.ConsumeAsync(), Times.Once);
|
||||
}
|
||||
|
||||
private static async Task WaitForCondition(TimeSpan timeout, Func<bool> condition)
|
||||
{
|
||||
const int MaxWaitLoop = 150;
|
||||
|
|
|
|||
|
|
@ -25,9 +25,16 @@ namespace Microsoft.AspNetCore.Testing
|
|||
set => _keepAlive = value;
|
||||
}
|
||||
|
||||
public MessageBody NextMessageBody { private get; set; }
|
||||
|
||||
public Task ProduceEndAsync()
|
||||
{
|
||||
return ProduceEnd();
|
||||
}
|
||||
|
||||
protected override MessageBody CreateMessageBody()
|
||||
{
|
||||
return NextMessageBody ?? base.CreateMessageBody();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue