-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
HttpMethodMetadata.cs
61 lines (53 loc) · 2.17 KB
/
HttpMethodMetadata.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
using System.Linq;
using Microsoft.AspNetCore.Shared;
using static Microsoft.AspNetCore.Http.HttpMethods;
namespace Microsoft.AspNetCore.Routing;
/// <summary>
/// Represents HTTP method metadata used during routing.
/// </summary>
[DebuggerDisplay("{ToString(),nq}")]
public sealed class HttpMethodMetadata : IHttpMethodMetadata
{
/// <summary>
/// Initializes a new instance of the <see cref="HttpMethodMetadata" /> class.
/// </summary>
/// <param name="httpMethods">
/// The HTTP methods used during routing.
/// An empty collection means any HTTP method will be accepted.
/// </param>
public HttpMethodMetadata(IEnumerable<string> httpMethods)
: this(httpMethods, acceptCorsPreflight: false)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="HttpMethodMetadata" /> class.
/// </summary>
/// <param name="httpMethods">
/// The HTTP methods used during routing.
/// An empty collection means any HTTP method will be accepted.
/// </param>
/// <param name="acceptCorsPreflight">A value indicating whether routing accepts CORS preflight requests.</param>
public HttpMethodMetadata(IEnumerable<string> httpMethods, bool acceptCorsPreflight)
{
ArgumentNullException.ThrowIfNull(httpMethods);
HttpMethods = httpMethods.Select(GetCanonicalizedValue).ToArray();
AcceptCorsPreflight = acceptCorsPreflight;
}
/// <summary>
/// Returns a value indicating whether the associated endpoint should accept CORS preflight requests.
/// </summary>
public bool AcceptCorsPreflight { get; set; }
/// <summary>
/// Returns a read-only collection of HTTP methods used during routing.
/// An empty collection means any HTTP method will be accepted.
/// </summary>
public IReadOnlyList<string> HttpMethods { get; }
/// <inheritdoc/>
public override string ToString()
{
return DebuggerHelpers.GetDebugText(nameof(HttpMethods), HttpMethods, "Cors", AcceptCorsPreflight);
}
}