From 84916223bbc0364ab71a2c3a0f521ddbcf02368a Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Tue, 16 Apr 2019 10:35:49 -0700 Subject: [PATCH] Address Bens cool feedback --- .../Routing/src/Matching/HttpMethodMatcherPolicy.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Http/Routing/src/Matching/HttpMethodMatcherPolicy.cs b/src/Http/Routing/src/Matching/HttpMethodMatcherPolicy.cs index d6ef3bbda2..6e7d2d069b 100644 --- a/src/Http/Routing/src/Matching/HttpMethodMatcherPolicy.cs +++ b/src/Http/Routing/src/Matching/HttpMethodMatcherPolicy.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Routing.Matching { @@ -136,10 +137,11 @@ namespace Microsoft.AspNetCore.Routing.Matching } var httpMethod = httpContext.Request.Method; + var headers = httpContext.Request.Headers; if (metadata.AcceptCorsPreflight && string.Equals(httpMethod, PreflightHttpMethod, StringComparison.OrdinalIgnoreCase) && - httpContext.Request.Headers.ContainsKey(OriginHeader) && - httpContext.Request.Headers.TryGetValue(AccessControlRequestMethod, out var accessControlRequestMethod) && + headers.ContainsKey(HeaderNames.Origin) && + headers.TryGetValue(HeaderNames.AccessControlRequestMethod, out var accessControlRequestMethod) && !StringValues.IsNullOrEmpty(accessControlRequestMethod)) { needs405Endpoint = false; // We don't return a 405 for a CORS preflight request when the endpoints accept CORS preflight. @@ -438,10 +440,11 @@ namespace Microsoft.AspNetCore.Routing.Matching int destination; var httpMethod = httpContext.Request.Method; + var headers = httpContext.Request.Headers; if (_supportsCorsPreflight && string.Equals(httpMethod, PreflightHttpMethod, StringComparison.OrdinalIgnoreCase) && - httpContext.Request.Headers.ContainsKey(OriginHeader) && - httpContext.Request.Headers.TryGetValue(AccessControlRequestMethod, out var accessControlRequestMethod) && + headers.ContainsKey(HeaderNames.Origin) && + headers.TryGetValue(HeaderNames.AccessControlRequestMethod, out var accessControlRequestMethod) && !StringValues.IsNullOrEmpty(accessControlRequestMethod)) { return _corsPreflightDestinations != null &&