Stop writing responses after the unexpected end of request content (#2734)

This commit is contained in:
Stephen Halter 2018-07-19 14:18:57 -07:00 committed by GitHub
parent b934e46161
commit 603cd03bfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -91,8 +91,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
// Read() will have already have greedily consumed the entire request body if able.
if (result.IsCompleted)
{
// OnInputOrOutputCompleted() is an idempotent method that closes the connection. Sometimes
// input completion is observed here before the Input.OnWriterCompleted() callback is fired,
// so we call OnInputOrOutputCompleted() now to prevent a race in our tests where a 400
// response is written after observing the unexpected end of request content instead of just
// closing the connection without a response as expected.
_context.OnInputOrOutputCompleted();
// Treat any FIN from an upgraded request as expected.
// It's up to higher-level consumer (i.e. WebSocket middleware) to determine
// It's up to higher-level consumer (i.e. WebSocket middleware) to determine
// if the end is actually expected based on higher-level framing.
if (RequestUpgrade)
{

View File

@ -1302,11 +1302,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
? target.GetAsciiStringEscaped(Constants.MaxExceptionDetailSize)
: string.Empty);
public void SetBadRequestState(RequestRejectionReason reason)
{
SetBadRequestState(BadHttpRequestException.GetException(reason));
}
public void SetBadRequestState(BadHttpRequestException ex)
{
Log.ConnectionBadRequest(ConnectionId, ex);