Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HttpMethod.cs
Go to the documentation of this file.
4
5namespace System.Net.Http;
6
7public class HttpMethod : IEquatable<HttpMethod>
8{
9 private readonly string _method;
10
11 private readonly int? _http3Index;
12
13 private int _hashcode;
14
15 private static readonly HttpMethod s_getMethod = new HttpMethod("GET", 17);
16
17 private static readonly HttpMethod s_putMethod = new HttpMethod("PUT", 21);
18
19 private static readonly HttpMethod s_postMethod = new HttpMethod("POST", 20);
20
21 private static readonly HttpMethod s_deleteMethod = new HttpMethod("DELETE", 16);
22
23 private static readonly HttpMethod s_headMethod = new HttpMethod("HEAD", 18);
24
25 private static readonly HttpMethod s_optionsMethod = new HttpMethod("OPTIONS", 19);
26
27 private static readonly HttpMethod s_traceMethod = new HttpMethod("TRACE", -1);
28
29 private static readonly HttpMethod s_patchMethod = new HttpMethod("PATCH", -1);
30
31 private static readonly HttpMethod s_connectMethod = new HttpMethod("CONNECT", 15);
32
33 private byte[] _http3EncodedBytes;
34
35 public static HttpMethod Get => s_getMethod;
36
37 public static HttpMethod Put => s_putMethod;
38
39 public static HttpMethod Post => s_postMethod;
40
42
43 public static HttpMethod Head => s_headMethod;
44
46
47 public static HttpMethod Trace => s_traceMethod;
48
49 public static HttpMethod Patch => s_patchMethod;
50
52
53 public string Method => _method;
54
55 internal bool MustHaveRequestBody
56 {
57 get
58 {
59 if ((object)this != Get && (object)this != Head && (object)this != Connect && (object)this != Options)
60 {
61 return (object)this != Delete;
62 }
63 return false;
64 }
65 }
66
67 internal byte[] Http3EncodedBytes
68 {
69 get
70 {
72 ref byte[] http3EncodedBytes;
73 byte[] array2;
74 if (array == null)
75 {
76 http3EncodedBytes = ref _http3EncodedBytes;
77 int? http3Index = _http3Index;
78 if (http3Index.HasValue)
79 {
80 int valueOrDefault = http3Index.GetValueOrDefault();
81 if (valueOrDefault >= 0)
82 {
84 goto IL_0046;
85 }
86 }
88 goto IL_0046;
89 }
90 goto IL_004d;
91 IL_004d:
92 return array;
93 IL_0046:
94 array = array2;
95 Volatile.Write(ref http3EncodedBytes, array2);
96 goto IL_004d;
97 }
98 }
99
100 public HttpMethod(string method)
101 {
102 if (string.IsNullOrEmpty(method))
103 {
105 }
106 if (HttpRuleParser.GetTokenLength(method, 0) != method.Length)
107 {
109 }
110 _method = method;
111 }
112
113 private HttpMethod(string method, int http3StaticTableIndex)
114 {
115 _method = method;
116 _http3Index = http3StaticTableIndex;
117 }
118
119 public bool Equals([NotNullWhen(true)] HttpMethod? other)
120 {
121 if ((object)other == null)
122 {
123 return false;
124 }
125 if ((object)_method == other._method)
126 {
127 return true;
128 }
129 return string.Equals(_method, other._method, StringComparison.OrdinalIgnoreCase);
130 }
131
132 public override bool Equals([NotNullWhen(true)] object? obj)
133 {
134 return Equals(obj as HttpMethod);
135 }
136
137 public override int GetHashCode()
138 {
139 if (_hashcode == 0)
140 {
142 }
143 return _hashcode;
144 }
145
146 public override string ToString()
147 {
148 return _method;
149 }
150
151 public static bool operator ==(HttpMethod? left, HttpMethod? right)
152 {
153 if ((object)left != null && (object)right != null)
154 {
155 return left.Equals(right);
156 }
157 return (object)left == right;
158 }
159
160 public static bool operator !=(HttpMethod? left, HttpMethod? right)
161 {
162 return !(left == right);
163 }
164
165 internal static HttpMethod Normalize(HttpMethod method)
166 {
167 int? http3Index = method._http3Index;
168 if (!http3Index.HasValue && method._method.Length >= 3)
169 {
170 HttpMethod httpMethod = (method._method[0] | 0x20) switch
171 {
172 99 => s_connectMethod,
173 100 => s_deleteMethod,
174 103 => s_getMethod,
175 104 => s_headMethod,
176 111 => s_optionsMethod,
177 112 => method._method.Length switch
178 {
179 3 => s_putMethod,
180 4 => s_postMethod,
181 _ => s_patchMethod,
182 },
183 116 => s_traceMethod,
184 _ => null,
185 };
186 if ((object)httpMethod != null && string.Equals(method._method, httpMethod._method, StringComparison.OrdinalIgnoreCase))
187 {
188 return httpMethod;
189 }
190 }
191 return method;
192 }
193}
HttpMethod(string method)
static readonly HttpMethod s_patchMethod
Definition HttpMethod.cs:29
static HttpMethod Options
Definition HttpMethod.cs:45
static readonly HttpMethod s_optionsMethod
Definition HttpMethod.cs:25
static readonly HttpMethod s_postMethod
Definition HttpMethod.cs:19
HttpMethod(string method, int http3StaticTableIndex)
bool Equals([NotNullWhen(true)] HttpMethod? other)
static HttpMethod Head
Definition HttpMethod.cs:43
override bool Equals([NotNullWhen(true)] object? obj)
static readonly HttpMethod s_traceMethod
Definition HttpMethod.cs:27
static readonly HttpMethod s_connectMethod
Definition HttpMethod.cs:31
readonly? int _http3Index
Definition HttpMethod.cs:11
static HttpMethod Patch
Definition HttpMethod.cs:49
static HttpMethod Delete
Definition HttpMethod.cs:41
static readonly HttpMethod s_headMethod
Definition HttpMethod.cs:23
static HttpMethod Normalize(HttpMethod method)
readonly string _method
Definition HttpMethod.cs:9
static HttpMethod Get
Definition HttpMethod.cs:35
static readonly HttpMethod s_deleteMethod
Definition HttpMethod.cs:21
override int GetHashCode()
static bool operator!=(HttpMethod? left, HttpMethod? right)
override string ToString()
static HttpMethod Post
Definition HttpMethod.cs:39
static readonly HttpMethod s_getMethod
Definition HttpMethod.cs:15
static HttpMethod Put
Definition HttpMethod.cs:37
static HttpMethod Connect
Definition HttpMethod.cs:51
static readonly HttpMethod s_putMethod
Definition HttpMethod.cs:17
static bool operator==(HttpMethod? left, HttpMethod? right)
static int GetTokenLength(string input, int startIndex)
static byte[] EncodeStaticIndexedHeaderFieldToArray(int index)
static byte[] EncodeLiteralHeaderFieldWithStaticNameReferenceToArray(int index)
static string net_http_argument_empty_string
Definition SR.cs:52
static string net_http_httpmethod_format_error
Definition SR.cs:14
Definition SR.cs:7
static StringComparer OrdinalIgnoreCase
static bool Read(ref bool location)
Definition Volatile.cs:67
static void Write(ref bool location, bool value)
Definition Volatile.cs:74