Address Bens cool feedback

This commit is contained in:
Ryan Nowak 2019-04-16 10:35:49 -07:00 committed by Ryan Nowak
parent 7021df89e4
commit 84916223bb
1 changed files with 7 additions and 4 deletions

View File

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Internal; using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNetCore.Routing.Matching namespace Microsoft.AspNetCore.Routing.Matching
{ {
@ -136,10 +137,11 @@ namespace Microsoft.AspNetCore.Routing.Matching
} }
var httpMethod = httpContext.Request.Method; var httpMethod = httpContext.Request.Method;
var headers = httpContext.Request.Headers;
if (metadata.AcceptCorsPreflight && if (metadata.AcceptCorsPreflight &&
string.Equals(httpMethod, PreflightHttpMethod, StringComparison.OrdinalIgnoreCase) && string.Equals(httpMethod, PreflightHttpMethod, StringComparison.OrdinalIgnoreCase) &&
httpContext.Request.Headers.ContainsKey(OriginHeader) && headers.ContainsKey(HeaderNames.Origin) &&
httpContext.Request.Headers.TryGetValue(AccessControlRequestMethod, out var accessControlRequestMethod) && headers.TryGetValue(HeaderNames.AccessControlRequestMethod, out var accessControlRequestMethod) &&
!StringValues.IsNullOrEmpty(accessControlRequestMethod)) !StringValues.IsNullOrEmpty(accessControlRequestMethod))
{ {
needs405Endpoint = false; // We don't return a 405 for a CORS preflight request when the endpoints accept CORS preflight. 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; int destination;
var httpMethod = httpContext.Request.Method; var httpMethod = httpContext.Request.Method;
var headers = httpContext.Request.Headers;
if (_supportsCorsPreflight && if (_supportsCorsPreflight &&
string.Equals(httpMethod, PreflightHttpMethod, StringComparison.OrdinalIgnoreCase) && string.Equals(httpMethod, PreflightHttpMethod, StringComparison.OrdinalIgnoreCase) &&
httpContext.Request.Headers.ContainsKey(OriginHeader) && headers.ContainsKey(HeaderNames.Origin) &&
httpContext.Request.Headers.TryGetValue(AccessControlRequestMethod, out var accessControlRequestMethod) && headers.TryGetValue(HeaderNames.AccessControlRequestMethod, out var accessControlRequestMethod) &&
!StringValues.IsNullOrEmpty(accessControlRequestMethod)) !StringValues.IsNullOrEmpty(accessControlRequestMethod))
{ {
return _corsPreflightDestinations != null && return _corsPreflightDestinations != null &&