Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit f48276f

Browse files
halter73benaadams
authored andcommitted
Consume the full request body when the app does not
1 parent 3db3b44 commit f48276f

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ public async Task RequestProcessingAsync()
196196
await FireOnCompleted();
197197

198198
await ProduceEnd();
199+
200+
// Finish reading the request body in case the app did not.
201+
await RequestBody.CopyToAsync(Stream.Null);
199202
}
200203

201204
terminated = !_keepAlive;

test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,52 @@ await connection.ReceiveEnd(
876876
}
877877
}
878878

879+
[Theory]
880+
[MemberData(nameof(ConnectionFilterData))]
881+
public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(ServiceContext testContext)
882+
{
883+
using (var server = new TestServer(async frame =>
884+
{
885+
var response = frame.Get<IHttpResponseFeature>();
886+
var request = frame.Get<IHttpRequestFeature>();
887+
888+
Assert.Equal("POST", request.Method);
889+
890+
response.Headers.Clear();
891+
response.Headers["Content-Length"] = new[] { "11" };
892+
893+
await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11);
894+
}, testContext))
895+
{
896+
using (var connection = new TestConnection())
897+
{
898+
await connection.SendEnd(
899+
"POST / HTTP/1.1",
900+
"Content-Length: 5",
901+
"",
902+
"HelloPOST / HTTP/1.1",
903+
"Transfer-Encoding: chunked",
904+
"",
905+
"C", "HelloChunked", "0",
906+
"POST / HTTP/1.1",
907+
"Content-Length: 7",
908+
"",
909+
"Goodbye");
910+
await connection.ReceiveEnd(
911+
"HTTP/1.1 200 OK",
912+
"Content-Length: 11",
913+
"",
914+
"Hello WorldHTTP/1.1 200 OK",
915+
"Content-Length: 11",
916+
"",
917+
"Hello WorldHTTP/1.1 200 OK",
918+
"Content-Length: 11",
919+
"",
920+
"Hello World");
921+
}
922+
}
923+
}
924+
879925
private class TestApplicationErrorLogger : ILogger
880926
{
881927
public int ApplicationErrorsLogged { get; set; }

0 commit comments

Comments
 (0)