Skip to content

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

@hamidrezahy

Description

@hamidrezahy

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;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions