Repository navigation
Expand file tree
/
Copy pathCorsRequestContext.cs
More file actions
98 lines (87 loc) · 3.35 KB
/
Copy pathCorsRequestContext.cs
File metadata and controls
98 lines (87 loc) · 3.35 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// 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 System.Collections.Generic;
using System.Text;
namespace System.Web.Cors
{
/// <summary>
/// Provides access to CORS-specific information on the request.
/// </summary>
public class CorsRequestContext
{
/// <summary>
/// Initializes a new instance of the <see cref="CorsRequestContext"/> class.
/// </summary>
public CorsRequestContext()
{
AccessControlRequestHeaders = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
Properties = new Dictionary<string, object>();
}
/// <summary>
/// Gets or sets the request URI.
/// </summary>
public Uri RequestUri { get; set; }
/// <summary>
/// Gets or sets the request method.
/// </summary>
public string HttpMethod { get; set; }
/// <summary>
/// Gets or sets the Origin header value.
/// </summary>
public string Origin { get; set; }
/// <summary>
/// Gets or sets the Host header value.
/// </summary>
public string Host { get; set; }
/// <summary>
/// Gets or sets the Access-Control-Request-Method header value.
/// </summary>
public string AccessControlRequestMethod { get; set; }
/// <summary>
/// Gets the Access-Control-Request-Headers header value.
/// </summary>
public ISet<string> AccessControlRequestHeaders { get; private set; }
/// <summary>
/// Gets a set of properties for the <see cref="CorsRequestContext"/>.
/// </summary>
public IDictionary<string, object> Properties { get; private set; }
/// <summary>
/// Gets a value indicating whether this is a preflight request.
/// </summary>
public bool IsPreflight
{
get
{
return Origin != null &&
AccessControlRequestMethod != null &&
String.Equals(HttpMethod, CorsConstants.PreflightHttpMethod, StringComparison.OrdinalIgnoreCase);
}
}
/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String" /> that represents this instance.
/// </returns>
public override string ToString()
{
StringBuilder builder = new StringBuilder();
builder.Append("Origin: ");
builder.Append(Origin ?? "null");
builder.Append(", HttpMethod: ");
builder.Append(HttpMethod ?? "null");
builder.Append(", IsPreflight: ");
builder.Append(IsPreflight);
builder.Append(", Host: ");
builder.Append(Host);
builder.Append(", AccessControlRequestMethod: ");
builder.Append(AccessControlRequestMethod ?? "null");
builder.Append(", RequestUri: ");
builder.Append(RequestUri);
builder.Append(", AccessControlRequestHeaders: {");
builder.Append(String.Join(",", AccessControlRequestHeaders));
builder.Append("}");
return builder.ToString();
}
}
}