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

Commit 7f1ffa0

Browse files
author
Cesar Blum Silveira
committed
Avoid slowing down common scenario.
1 parent a899549 commit 7f1ffa0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,16 @@ public static MessageBody For(
281281
}
282282
}
283283

284-
// If we got here, request contains no Content-Length or Transfer-Encoding header.
285-
// Reject with 411 Length Required.
286-
if (HttpMethods.IsPost(context.Method) || HttpMethods.IsPut(context.Method))
284+
// Avoid slowing down most common case
285+
if (!object.ReferenceEquals(context.Method, HttpMethods.Get))
287286
{
288-
var requestRejectionReason = httpVersion == HttpVersion.Http11 ? RequestRejectionReason.LengthRequired : RequestRejectionReason.LengthRequiredHttp10;
289-
context.RejectRequest(requestRejectionReason, context.Method);
287+
// If we got here, request contains no Content-Length or Transfer-Encoding header.
288+
// Reject with 411 Length Required.
289+
if (HttpMethods.IsPost(context.Method) || HttpMethods.IsPut(context.Method))
290+
{
291+
var requestRejectionReason = httpVersion == HttpVersion.Http11 ? RequestRejectionReason.LengthRequired : RequestRejectionReason.LengthRequiredHttp10;
292+
context.RejectRequest(requestRejectionReason, context.Method);
293+
}
290294
}
291295

292296
return new ForContentLength(keepAlive, 0, context);

0 commit comments

Comments
 (0)