Skip to content

Commit 8be8e00

Browse files
benaadamspakrym
authored andcommitted
Avoid boxing context.Method (#5687)
1 parent cb1917a commit 8be8e00

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/Servers/Kestrel/Core/src/Internal/Http/Http1MessageBody.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,12 @@ public static MessageBody For(
280280
return new ForContentLength(keepAlive, contentLength, context);
281281
}
282282

283-
// Avoid slowing down most common case
284-
if (!object.ReferenceEquals(context.Method, HttpMethods.Get))
283+
// If we got here, request contains no Content-Length or Transfer-Encoding header.
284+
// Reject with 411 Length Required.
285+
if (context.Method == HttpMethod.Post || context.Method == HttpMethod.Put)
285286
{
286-
// If we got here, request contains no Content-Length or Transfer-Encoding header.
287-
// Reject with 411 Length Required.
288-
if (context.Method == HttpMethod.Post || context.Method == HttpMethod.Put)
289-
{
290-
var requestRejectionReason = httpVersion == HttpVersion.Http11 ? RequestRejectionReason.LengthRequired : RequestRejectionReason.LengthRequiredHttp10;
291-
BadHttpRequestException.Throw(requestRejectionReason, context.Method);
292-
}
287+
var requestRejectionReason = httpVersion == HttpVersion.Http11 ? RequestRejectionReason.LengthRequired : RequestRejectionReason.LengthRequiredHttp10;
288+
BadHttpRequestException.Throw(requestRejectionReason, context.Method);
293289
}
294290

295291
return keepAlive ? MessageBody.ZeroContentLengthKeepAlive : MessageBody.ZeroContentLengthClose;

0 commit comments

Comments
 (0)