Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AnyHeader and AnyMethod to src/Middleware/CORS/src/Infrastructure/CorsConstants.cs #54772

Open
hamidrezahy opened this issue Mar 26, 2024 · 2 comments · May be fixed by #55650
Open

Add AnyHeader and AnyMethod to src/Middleware/CORS/src/Infrastructure/CorsConstants.cs #54772

hamidrezahy opened this issue Mar 26, 2024 · 2 comments · May be fixed by #55650
Labels
api-approved API was approved in API review, it can be implemented area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Comments

@hamidrezahy
Copy link

Background and Motivation

According to pull request #54247, CorsConstants only contain AnyOrigin value

This is while it also needs AnyHeaders and AnyMethods because, unlike AnyOrigin, the value "*" is used directly in other places.

Proposed API

My changes are like this:

namespace Microsoft.AspNetCore.Cors.Infrastructure;

public static class CorsConstants
{
+    public static readonly string AnyHeader = "*";
+    public static readonly string AnyMethod = "*";
}

Usage Examples

public bool AllowAnyHeader
{
    get
    {
        if (Headers == null || Headers.Count != 1 || Headers[0] != CorsConstants.AnyHeader)
        {
            return false;
        }
        return true;
    }
}
public bool AllowAnyMethod
{
    get
    {
        if (Methods == null || Methods.Count != 1 || Methods[0] != CorsConstants.AnyMethod)
        {
            return false;
        }
        return true;
    }
}

Instead of using this form:

public bool AllowAnyHeader
{
    get
    {
        if (Headers == null || Headers.Count != 1 || Headers[0] != "*")
        {
            return false;
        }
        return true;
    }
}
public bool AllowAnyMethod
{
    get
    {
        if (Methods == null || Methods.Count != 1 || Methods[0] != "*")
        {
            return false;
        }
        return true;
    }
}
@hamidrezahy hamidrezahy added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Mar 26, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Mar 26, 2024
@amcasey amcasey added api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Mar 26, 2024
Copy link
Contributor

Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:

  • The PR contains changes to the reference-assembly that describe the API change. Or, you have included a snippet of reference-assembly-style code that illustrates the API change.
  • The PR describes the impact to users, both positive (useful new APIs) and negative (breaking changes).
  • Someone is assigned to "champion" this change in the meeting, and they understand the impact and design of the change.

@amcasey
Copy link
Member

amcasey commented Mar 28, 2024

API Approved!

@amcasey amcasey added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews labels Mar 28, 2024
@I-SER-I I-SER-I linked a pull request May 9, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved API was approved in API review, it can be implemented area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants