Skip to content

Commit 8ca21f8

Browse files
committed
PR feedback
1 parent 02de72d commit 8ca21f8

File tree

5 files changed

+12
-18
lines changed

5 files changed

+12
-18
lines changed

src/Middleware/CORS/src/CorsPolicyMetadata.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55

66
namespace Microsoft.AspNetCore.Cors
77
{
8+
/// <summary>
9+
/// Metadata that provides a CORS policy.
10+
/// </summary>
811
public class CorsPolicyMetadata : ICorsPolicyMetadata
912
{
1013
public CorsPolicyMetadata(CorsPolicy policy)
1114
{
1215
Policy = policy;
1316
}
1417

15-
public CorsPolicyMetadata(string policyName)
16-
{
17-
PolicyName = policyName;
18-
}
19-
18+
/// <summary>
19+
/// The policy which needs to be applied.
20+
/// </summary>
2021
public CorsPolicy Policy { get; }
21-
22-
public string PolicyName { get; }
2322
}
2423
}

src/Middleware/CORS/src/Infrastructure/CorsEndpointConventionBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static IEndpointConventionBuilder WithCorsPolicy(this IEndpointConvention
2828

2929
builder.Apply(endpointBuilder =>
3030
{
31-
endpointBuilder.Metadata.Add(new CorsPolicyMetadata(policyName));
31+
endpointBuilder.Metadata.Add(new EnableCorsAttribute(policyName));
3232
});
3333
return builder;
3434
}

src/Middleware/CORS/src/Infrastructure/CorsMiddleware.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ private async Task InvokeCore(HttpContext context, ICorsPolicyProvider corsPolic
131131
// CORS policy resolution rules:
132132
//
133133
// 1. If there is an endpoint with IDisableCorsAttribute then CORS is not run
134-
// 2. If there is an endpoint with ICorsPolicyMetadata then use its policy and name
135-
// 3. If there is an endpoint with IEnableCorsAttribute that has a policy name then
134+
// 2. If there is an endpoint with ICorsPolicyMetadata then use its policy or if
135+
// there is an endpoint with IEnableCorsAttribute that has a policy name then
136136
// fetch policy by name, prioritizing it above policy on middleware
137-
// 4. If there is no policy on middleware then use name on middleware
137+
// 3. If there is no policy on middleware then use name on middleware
138138

139139
// Flag to indicate to other systems, e.g. MVC, that CORS middleware was run for this request
140140
context.Items[CorsMiddlewareInvokedKey] = true;
@@ -154,7 +154,7 @@ private async Task InvokeCore(HttpContext context, ICorsPolicyProvider corsPolic
154154
var policyName = _corsPolicyName;
155155
if (corsMetadata is ICorsPolicyMetadata corsPolicyMetadata)
156156
{
157-
policyName = corsPolicyMetadata.PolicyName;
157+
policyName = null;
158158
corsPolicy = corsPolicyMetadata.Policy;
159159
}
160160
else if (corsMetadata is IEnableCorsAttribute enableCorsAttribute &&

src/Middleware/CORS/src/Infrastructure/ICorsPolicyMetadata.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,5 @@ public interface ICorsPolicyMetadata : ICorsMetadata
1212
/// The policy which needs to be applied.
1313
/// </summary>
1414
CorsPolicy Policy { get; }
15-
16-
/// <summary>
17-
/// The name of the policy which needs to be applied.
18-
/// </summary>
19-
string PolicyName { get; }
2015
}
2116
}

src/Middleware/CORS/test/UnitTests/CorsEndpointConventionBuilderExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void WithCorsPolicy_Name_MetadataAdded()
2828
addCorsPolicy(endpointModel);
2929
var endpoint = endpointModel.Build();
3030

31-
var metadata = endpoint.Metadata.GetMetadata<ICorsPolicyMetadata>();
31+
var metadata = endpoint.Metadata.GetMetadata<IEnableCorsAttribute>();
3232
Assert.NotNull(metadata);
3333
Assert.Equal("TestPolicyName", metadata.PolicyName);
3434
}

0 commit comments

Comments
 (0)