[Fixes #6547] Re-introduce HttpMethodActionConstraint dictionary perf improvement

This commit is contained in:
Javier Calvarro Nelson 2017-12-29 18:56:22 -08:00 committed by GitHub
parent 82e32240a4
commit 57c8b71b4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -35,8 +35,9 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
}
var request = context.RouteContext.HttpContext.Request;
if (request.Headers.ContainsKey(OriginHeader) &&
string.Equals(request.Method, PreflightHttpMethod, StringComparison.OrdinalIgnoreCase) &&
// Perf: Check http method before accessing the Headers collection.
if (string.Equals(request.Method, PreflightHttpMethod, StringComparison.OrdinalIgnoreCase) &&
request.Headers.ContainsKey(OriginHeader) &&
request.Headers.TryGetValue(AccessControlRequestMethod, out var accessControlRequestMethod) &&
!StringValues.IsNullOrEmpty(accessControlRequestMethod))
{