From 69e051dab78988f4a9bac9da01a737aa1b53c77b Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Fri, 12 Jun 2015 17:20:19 -0700 Subject: [PATCH] Removed Cors.Core dependency from Mvc.Core --- src/Microsoft.AspNet.Mvc.Core/HttpMethodConstraint.cs | 11 +++++++---- .../MvcCoreServiceCollectionExtensions.cs | 1 - src/Microsoft.AspNet.Mvc.Core/project.json | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.Core/HttpMethodConstraint.cs b/src/Microsoft.AspNet.Mvc.Core/HttpMethodConstraint.cs index 3ee3da6cec..edabe282c8 100644 --- a/src/Microsoft.AspNet.Mvc.Core/HttpMethodConstraint.cs +++ b/src/Microsoft.AspNet.Mvc.Core/HttpMethodConstraint.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using Microsoft.AspNet.Cors.Core; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc @@ -16,6 +15,10 @@ public class HttpMethodConstraint : IActionConstraint private readonly IReadOnlyList _methods; + private readonly string OriginHeader = "Origin"; + private readonly string AccessControlRequestMethod = "Access-Control-Request-Method"; + private readonly string PreflightHttpMethod = "OPTIONS"; + // Empty collection means any method will be accepted. public HttpMethodConstraint([NotNull] IEnumerable httpMethods) { @@ -56,13 +59,13 @@ public bool Accept([NotNull] ActionConstraintContext context) var request = context.RouteContext.HttpContext.Request; var method = request.Method; - if (request.Headers.ContainsKey(CorsConstants.Origin)) + if (request.Headers.ContainsKey(OriginHeader)) { // Update the http method if it is preflight request. - var accessControlRequestMethod = request.Headers.Get(CorsConstants.AccessControlRequestMethod); + var accessControlRequestMethod = request.Headers.Get(AccessControlRequestMethod); if (string.Equals( request.Method, - CorsConstants.PreflightHttpMethod, + PreflightHttpMethod, StringComparison.Ordinal) && accessControlRequestMethod != null) { diff --git a/src/Microsoft.AspNet.Mvc.Core/MvcCoreServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/MvcCoreServiceCollectionExtensions.cs index 11544de30b..1a8d82aa57 100644 --- a/src/Microsoft.AspNet.Mvc.Core/MvcCoreServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/MvcCoreServiceCollectionExtensions.cs @@ -152,7 +152,6 @@ private static void ConfigureDefaultServices(IServiceCollection services) { services.AddOptions(); services.AddRouting(); - services.AddCors(); services.AddNotifier(); services.Configure( routeOptions => routeOptions.ConstraintMap.Add("exists", typeof(KnownRouteValueConstraint))); diff --git a/src/Microsoft.AspNet.Mvc.Core/project.json b/src/Microsoft.AspNet.Mvc.Core/project.json index b4ccf7cb1f..2594448f38 100644 --- a/src/Microsoft.AspNet.Mvc.Core/project.json +++ b/src/Microsoft.AspNet.Mvc.Core/project.json @@ -5,8 +5,8 @@ "warningsAsErrors": true }, "dependencies": { - "Microsoft.AspNet.Cors.Core": "1.0.0-*", "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*", + "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.Mvc.Abstractions": "6.0.0-*", "Microsoft.AspNet.Mvc.Common": { "version": "6.0.0-*", "type": "build" }, "Microsoft.AspNet.WebUtilities": "1.0.0-*",