From 58411b4cc4badb5ade2c4960c90e6ebf3e1daf2c Mon Sep 17 00:00:00 2001 From: Priyanshu Agrawal Date: Sat, 3 Feb 2018 01:24:56 +0530 Subject: [PATCH 1/3] Use header names from HttpAbstractions Closes aspnet/Home#2319 This will use constants defined in HeaderNames class instead of hard coded strings. --- .../Infrastructure/CorsConstants.cs | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.AspNetCore.Cors/Infrastructure/CorsConstants.cs b/src/Microsoft.AspNetCore.Cors/Infrastructure/CorsConstants.cs index 602f381..bc8a994 100644 --- a/src/Microsoft.AspNetCore.Cors/Infrastructure/CorsConstants.cs +++ b/src/Microsoft.AspNetCore.Cors/Infrastructure/CorsConstants.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.Net.Http.Headers; + namespace Microsoft.AspNetCore.Cors.Infrastructure { /// @@ -10,13 +12,13 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure { /// /// The HTTP method for the CORS preflight request. - /// + /// public static readonly string PreflightHttpMethod = "OPTIONS"; /// /// The Origin request header. /// - public static readonly string Origin = "Origin"; + public static readonly string Origin = HeaderNames.Origin; /// /// The value for the Access-Control-Allow-Origin response header to allow all origins. @@ -26,59 +28,60 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure /// /// The Access-Control-Request-Method request header. /// - public static readonly string AccessControlRequestMethod = "Access-Control-Request-Method"; + public static readonly string AccessControlRequestMethod = HeaderNames.AccessControlRequestMethod; /// /// The Access-Control-Request-Headers request header. /// - public static readonly string AccessControlRequestHeaders = "Access-Control-Request-Headers"; + public static readonly string AccessControlRequestHeaders = HeaderNames.AccessControlRequestHeaders; /// /// The Access-Control-Allow-Origin response header. /// - public static readonly string AccessControlAllowOrigin = "Access-Control-Allow-Origin"; + public static readonly string AccessControlAllowOrigin = HeaderNames.AccessControlAllowOrigin; /// /// The Access-Control-Allow-Headers response header. /// - public static readonly string AccessControlAllowHeaders = "Access-Control-Allow-Headers"; + public static readonly string AccessControlAllowHeaders = HeaderNames.AccessControlAllowHeaders; /// /// The Access-Control-Expose-Headers response header. /// - public static readonly string AccessControlExposeHeaders = "Access-Control-Expose-Headers"; + public static readonly string AccessControlExposeHeaders = HeaderNames.AccessControlExposeHeaders; /// /// The Access-Control-Allow-Methods response header. /// - public static readonly string AccessControlAllowMethods = "Access-Control-Allow-Methods"; + public static readonly string AccessControlAllowMethods = HeaderNames.AccessControlAllowMethods; /// /// The Access-Control-Allow-Credentials response header. /// - public static readonly string AccessControlAllowCredentials = "Access-Control-Allow-Credentials"; + public static readonly string AccessControlAllowCredentials = HeaderNames.AccessControlAllowCredentials; /// /// The Access-Control-Max-Age response header. /// - public static readonly string AccessControlMaxAge = "Access-Control-Max-Age"; + public static readonly string AccessControlMaxAge = HeaderNames.AccessControlMaxAge; + internal static readonly string[] SimpleRequestHeaders = { - "Origin", - "Accept", - "Accept-Language", - "Content-Language", + HeaderNames.Origin, + HeaderNames.Accept, + HeaderNames.AcceptLanguage, + HeaderNames.ContentLanguage, }; internal static readonly string[] SimpleResponseHeaders = { - "Cache-Control", - "Content-Language", - "Content-Type", - "Expires", - "Last-Modified", - "Pragma" + HeaderNames.CacheControl, + HeaderNames.ContentLanguage, + HeaderNames.ContentType, + HeaderNames.Expires, + HeaderNames.LastModified, + HeaderNames.Pragma }; internal static readonly string[] SimpleMethods = From e0e4b007ec1a73468a12e4dbb2333ef5348dfaad Mon Sep 17 00:00:00 2001 From: Priyanshu Agrawal Date: Sat, 3 Feb 2018 01:36:28 +0530 Subject: [PATCH 2/3] Use http method names from HttpAbstractions This uses http method names from strings defined HttpMethods class instead of hard coded strings. --- .../Infrastructure/CorsConstants.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Cors/Infrastructure/CorsConstants.cs b/src/Microsoft.AspNetCore.Cors/Infrastructure/CorsConstants.cs index bc8a994..8028f9e 100644 --- a/src/Microsoft.AspNetCore.Cors/Infrastructure/CorsConstants.cs +++ b/src/Microsoft.AspNetCore.Cors/Infrastructure/CorsConstants.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.AspNetCore.Http; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Cors.Infrastructure @@ -13,7 +14,7 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure /// /// The HTTP method for the CORS preflight request. /// - public static readonly string PreflightHttpMethod = "OPTIONS"; + public static readonly string PreflightHttpMethod = HttpMethods.Options; /// /// The Origin request header. @@ -86,9 +87,9 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure internal static readonly string[] SimpleMethods = { - "GET", - "HEAD", - "POST" + HttpMethods.Get, + HttpMethods.Head, + HttpMethods.Post }; } } \ No newline at end of file From ce82951c56b48395171b2a3e28911c6011c02217 Mon Sep 17 00:00:00 2001 From: Priyanshu Agrawal Date: Mon, 5 Feb 2018 23:52:53 +0530 Subject: [PATCH 3/3] Remove extra white-spaces --- src/Microsoft.AspNetCore.Cors/Infrastructure/CorsConstants.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Cors/Infrastructure/CorsConstants.cs b/src/Microsoft.AspNetCore.Cors/Infrastructure/CorsConstants.cs index 8028f9e..22110b2 100644 --- a/src/Microsoft.AspNetCore.Cors/Infrastructure/CorsConstants.cs +++ b/src/Microsoft.AspNetCore.Cors/Infrastructure/CorsConstants.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure { /// /// The HTTP method for the CORS preflight request. - /// + /// public static readonly string PreflightHttpMethod = HttpMethods.Options; ///