@@ -8,207 +8,138 @@ namespace System.Net.Http.HPack
8
8
{
9
9
internal static partial class StatusCodes
10
10
{
11
- // This uses C# compiler's ability to refer to static data directly. For more information see https://vcsjones.dev/2019/02/01/csharp-readonly-span-bytes-static
12
-
13
- private static ReadOnlySpan < byte > BytesStatus100 => new byte [ ] { ( byte ) '1' , ( byte ) '0' , ( byte ) '0' } ;
14
- private static ReadOnlySpan < byte > BytesStatus101 => new byte [ ] { ( byte ) '1' , ( byte ) '0' , ( byte ) '1' } ;
15
- private static ReadOnlySpan < byte > BytesStatus102 => new byte [ ] { ( byte ) '1' , ( byte ) '0' , ( byte ) '2' } ;
16
-
17
- private static ReadOnlySpan < byte > BytesStatus200 => new byte [ ] { ( byte ) '2' , ( byte ) '0' , ( byte ) '0' } ;
18
- private static ReadOnlySpan < byte > BytesStatus201 => new byte [ ] { ( byte ) '2' , ( byte ) '0' , ( byte ) '1' } ;
19
- private static ReadOnlySpan < byte > BytesStatus202 => new byte [ ] { ( byte ) '2' , ( byte ) '0' , ( byte ) '2' } ;
20
- private static ReadOnlySpan < byte > BytesStatus203 => new byte [ ] { ( byte ) '2' , ( byte ) '0' , ( byte ) '3' } ;
21
- private static ReadOnlySpan < byte > BytesStatus204 => new byte [ ] { ( byte ) '2' , ( byte ) '0' , ( byte ) '4' } ;
22
- private static ReadOnlySpan < byte > BytesStatus205 => new byte [ ] { ( byte ) '2' , ( byte ) '0' , ( byte ) '5' } ;
23
- private static ReadOnlySpan < byte > BytesStatus206 => new byte [ ] { ( byte ) '2' , ( byte ) '0' , ( byte ) '6' } ;
24
- private static ReadOnlySpan < byte > BytesStatus207 => new byte [ ] { ( byte ) '2' , ( byte ) '0' , ( byte ) '7' } ;
25
- private static ReadOnlySpan < byte > BytesStatus208 => new byte [ ] { ( byte ) '2' , ( byte ) '0' , ( byte ) '8' } ;
26
- private static ReadOnlySpan < byte > BytesStatus226 => new byte [ ] { ( byte ) '2' , ( byte ) '2' , ( byte ) '6' } ;
27
-
28
- private static ReadOnlySpan < byte > BytesStatus300 => new byte [ ] { ( byte ) '3' , ( byte ) '0' , ( byte ) '0' } ;
29
- private static ReadOnlySpan < byte > BytesStatus301 => new byte [ ] { ( byte ) '3' , ( byte ) '0' , ( byte ) '1' } ;
30
- private static ReadOnlySpan < byte > BytesStatus302 => new byte [ ] { ( byte ) '3' , ( byte ) '0' , ( byte ) '2' } ;
31
- private static ReadOnlySpan < byte > BytesStatus303 => new byte [ ] { ( byte ) '3' , ( byte ) '0' , ( byte ) '3' } ;
32
- private static ReadOnlySpan < byte > BytesStatus304 => new byte [ ] { ( byte ) '3' , ( byte ) '0' , ( byte ) '4' } ;
33
- private static ReadOnlySpan < byte > BytesStatus305 => new byte [ ] { ( byte ) '3' , ( byte ) '0' , ( byte ) '5' } ;
34
- private static ReadOnlySpan < byte > BytesStatus306 => new byte [ ] { ( byte ) '3' , ( byte ) '0' , ( byte ) '6' } ;
35
- private static ReadOnlySpan < byte > BytesStatus307 => new byte [ ] { ( byte ) '3' , ( byte ) '0' , ( byte ) '7' } ;
36
- private static ReadOnlySpan < byte > BytesStatus308 => new byte [ ] { ( byte ) '3' , ( byte ) '0' , ( byte ) '8' } ;
37
-
38
- private static ReadOnlySpan < byte > BytesStatus400 => new byte [ ] { ( byte ) '4' , ( byte ) '0' , ( byte ) '0' } ;
39
- private static ReadOnlySpan < byte > BytesStatus401 => new byte [ ] { ( byte ) '4' , ( byte ) '0' , ( byte ) '1' } ;
40
- private static ReadOnlySpan < byte > BytesStatus402 => new byte [ ] { ( byte ) '4' , ( byte ) '0' , ( byte ) '2' } ;
41
- private static ReadOnlySpan < byte > BytesStatus403 => new byte [ ] { ( byte ) '4' , ( byte ) '0' , ( byte ) '3' } ;
42
- private static ReadOnlySpan < byte > BytesStatus404 => new byte [ ] { ( byte ) '4' , ( byte ) '0' , ( byte ) '4' } ;
43
- private static ReadOnlySpan < byte > BytesStatus405 => new byte [ ] { ( byte ) '4' , ( byte ) '0' , ( byte ) '5' } ;
44
- private static ReadOnlySpan < byte > BytesStatus406 => new byte [ ] { ( byte ) '4' , ( byte ) '0' , ( byte ) '6' } ;
45
- private static ReadOnlySpan < byte > BytesStatus407 => new byte [ ] { ( byte ) '4' , ( byte ) '0' , ( byte ) '7' } ;
46
- private static ReadOnlySpan < byte > BytesStatus408 => new byte [ ] { ( byte ) '4' , ( byte ) '0' , ( byte ) '8' } ;
47
- private static ReadOnlySpan < byte > BytesStatus409 => new byte [ ] { ( byte ) '4' , ( byte ) '0' , ( byte ) '9' } ;
48
- private static ReadOnlySpan < byte > BytesStatus410 => new byte [ ] { ( byte ) '4' , ( byte ) '1' , ( byte ) '0' } ;
49
- private static ReadOnlySpan < byte > BytesStatus411 => new byte [ ] { ( byte ) '4' , ( byte ) '1' , ( byte ) '1' } ;
50
- private static ReadOnlySpan < byte > BytesStatus412 => new byte [ ] { ( byte ) '4' , ( byte ) '1' , ( byte ) '2' } ;
51
- private static ReadOnlySpan < byte > BytesStatus413 => new byte [ ] { ( byte ) '4' , ( byte ) '1' , ( byte ) '3' } ;
52
- private static ReadOnlySpan < byte > BytesStatus414 => new byte [ ] { ( byte ) '4' , ( byte ) '1' , ( byte ) '4' } ;
53
- private static ReadOnlySpan < byte > BytesStatus415 => new byte [ ] { ( byte ) '4' , ( byte ) '1' , ( byte ) '5' } ;
54
- private static ReadOnlySpan < byte > BytesStatus416 => new byte [ ] { ( byte ) '4' , ( byte ) '1' , ( byte ) '6' } ;
55
- private static ReadOnlySpan < byte > BytesStatus417 => new byte [ ] { ( byte ) '4' , ( byte ) '1' , ( byte ) '7' } ;
56
- private static ReadOnlySpan < byte > BytesStatus418 => new byte [ ] { ( byte ) '4' , ( byte ) '1' , ( byte ) '8' } ;
57
- private static ReadOnlySpan < byte > BytesStatus419 => new byte [ ] { ( byte ) '4' , ( byte ) '1' , ( byte ) '9' } ;
58
- private static ReadOnlySpan < byte > BytesStatus421 => new byte [ ] { ( byte ) '4' , ( byte ) '2' , ( byte ) '1' } ;
59
- private static ReadOnlySpan < byte > BytesStatus422 => new byte [ ] { ( byte ) '4' , ( byte ) '2' , ( byte ) '2' } ;
60
- private static ReadOnlySpan < byte > BytesStatus423 => new byte [ ] { ( byte ) '4' , ( byte ) '2' , ( byte ) '3' } ;
61
- private static ReadOnlySpan < byte > BytesStatus424 => new byte [ ] { ( byte ) '4' , ( byte ) '2' , ( byte ) '4' } ;
62
- private static ReadOnlySpan < byte > BytesStatus426 => new byte [ ] { ( byte ) '4' , ( byte ) '2' , ( byte ) '6' } ;
63
- private static ReadOnlySpan < byte > BytesStatus428 => new byte [ ] { ( byte ) '4' , ( byte ) '2' , ( byte ) '8' } ;
64
- private static ReadOnlySpan < byte > BytesStatus429 => new byte [ ] { ( byte ) '4' , ( byte ) '2' , ( byte ) '9' } ;
65
- private static ReadOnlySpan < byte > BytesStatus431 => new byte [ ] { ( byte ) '4' , ( byte ) '3' , ( byte ) '1' } ;
66
- private static ReadOnlySpan < byte > BytesStatus451 => new byte [ ] { ( byte ) '4' , ( byte ) '5' , ( byte ) '1' } ;
67
-
68
- private static ReadOnlySpan < byte > BytesStatus500 => new byte [ ] { ( byte ) '5' , ( byte ) '0' , ( byte ) '0' } ;
69
- private static ReadOnlySpan < byte > BytesStatus501 => new byte [ ] { ( byte ) '5' , ( byte ) '0' , ( byte ) '1' } ;
70
- private static ReadOnlySpan < byte > BytesStatus502 => new byte [ ] { ( byte ) '5' , ( byte ) '0' , ( byte ) '2' } ;
71
- private static ReadOnlySpan < byte > BytesStatus503 => new byte [ ] { ( byte ) '5' , ( byte ) '0' , ( byte ) '3' } ;
72
- private static ReadOnlySpan < byte > BytesStatus504 => new byte [ ] { ( byte ) '5' , ( byte ) '0' , ( byte ) '4' } ;
73
- private static ReadOnlySpan < byte > BytesStatus505 => new byte [ ] { ( byte ) '5' , ( byte ) '0' , ( byte ) '5' } ;
74
- private static ReadOnlySpan < byte > BytesStatus506 => new byte [ ] { ( byte ) '5' , ( byte ) '0' , ( byte ) '6' } ;
75
- private static ReadOnlySpan < byte > BytesStatus507 => new byte [ ] { ( byte ) '5' , ( byte ) '0' , ( byte ) '7' } ;
76
- private static ReadOnlySpan < byte > BytesStatus508 => new byte [ ] { ( byte ) '5' , ( byte ) '0' , ( byte ) '8' } ;
77
- private static ReadOnlySpan < byte > BytesStatus510 => new byte [ ] { ( byte ) '5' , ( byte ) '1' , ( byte ) '0' } ;
78
- private static ReadOnlySpan < byte > BytesStatus511 => new byte [ ] { ( byte ) '5' , ( byte ) '1' , ( byte ) '1' } ;
79
-
80
11
public static ReadOnlySpan < byte > ToStatusBytes ( int statusCode )
81
12
{
82
13
switch ( statusCode )
83
14
{
84
15
case ( int ) HttpStatusCode . Continue :
85
- return BytesStatus100 ;
16
+ return "100"u8 ;
86
17
case ( int ) HttpStatusCode . SwitchingProtocols :
87
- return BytesStatus101 ;
18
+ return "101"u8 ;
88
19
case ( int ) HttpStatusCode . Processing :
89
- return BytesStatus102 ;
20
+ return "102"u8 ;
90
21
91
22
case ( int ) HttpStatusCode . OK :
92
- return BytesStatus200 ;
23
+ return "200"u8 ;
93
24
case ( int ) HttpStatusCode . Created :
94
- return BytesStatus201 ;
25
+ return "201"u8 ;
95
26
case ( int ) HttpStatusCode . Accepted :
96
- return BytesStatus202 ;
27
+ return "202"u8 ;
97
28
case ( int ) HttpStatusCode . NonAuthoritativeInformation :
98
- return BytesStatus203 ;
29
+ return "203"u8 ;
99
30
case ( int ) HttpStatusCode . NoContent :
100
- return BytesStatus204 ;
31
+ return "204"u8 ;
101
32
case ( int ) HttpStatusCode . ResetContent :
102
- return BytesStatus205 ;
33
+ return "205"u8 ;
103
34
case ( int ) HttpStatusCode . PartialContent :
104
- return BytesStatus206 ;
35
+ return "206"u8 ;
105
36
case ( int ) HttpStatusCode . MultiStatus :
106
- return BytesStatus207 ;
37
+ return "207"u8 ;
107
38
case ( int ) HttpStatusCode . AlreadyReported :
108
- return BytesStatus208 ;
39
+ return "208"u8 ;
109
40
case ( int ) HttpStatusCode . IMUsed :
110
- return BytesStatus226 ;
41
+ return "226"u8 ;
111
42
112
43
case ( int ) HttpStatusCode . MultipleChoices :
113
- return BytesStatus300 ;
44
+ return "300"u8 ;
114
45
case ( int ) HttpStatusCode . MovedPermanently :
115
- return BytesStatus301 ;
46
+ return "301"u8 ;
116
47
case ( int ) HttpStatusCode . Found :
117
- return BytesStatus302 ;
48
+ return "302"u8 ;
118
49
case ( int ) HttpStatusCode . SeeOther :
119
- return BytesStatus303 ;
50
+ return "303"u8 ;
120
51
case ( int ) HttpStatusCode . NotModified :
121
- return BytesStatus304 ;
52
+ return "304"u8 ;
122
53
case ( int ) HttpStatusCode . UseProxy :
123
- return BytesStatus305 ;
54
+ return "305"u8 ;
124
55
case ( int ) HttpStatusCode . Unused :
125
- return BytesStatus306 ;
56
+ return "306"u8 ;
126
57
case ( int ) HttpStatusCode . TemporaryRedirect :
127
- return BytesStatus307 ;
58
+ return "307"u8 ;
128
59
case ( int ) HttpStatusCode . PermanentRedirect :
129
- return BytesStatus308 ;
60
+ return "308"u8 ;
130
61
131
62
case ( int ) HttpStatusCode . BadRequest :
132
- return BytesStatus400 ;
63
+ return "400"u8 ;
133
64
case ( int ) HttpStatusCode . Unauthorized :
134
- return BytesStatus401 ;
65
+ return "401"u8 ;
135
66
case ( int ) HttpStatusCode . PaymentRequired :
136
- return BytesStatus402 ;
67
+ return "402"u8 ;
137
68
case ( int ) HttpStatusCode . Forbidden :
138
- return BytesStatus403 ;
69
+ return "403"u8 ;
139
70
case ( int ) HttpStatusCode . NotFound :
140
- return BytesStatus404 ;
71
+ return "404"u8 ;
141
72
case ( int ) HttpStatusCode . MethodNotAllowed :
142
- return BytesStatus405 ;
73
+ return "405"u8 ;
143
74
case ( int ) HttpStatusCode . NotAcceptable :
144
- return BytesStatus406 ;
75
+ return "406"u8 ;
145
76
case ( int ) HttpStatusCode . ProxyAuthenticationRequired :
146
- return BytesStatus407 ;
77
+ return "407"u8 ;
147
78
case ( int ) HttpStatusCode . RequestTimeout :
148
- return BytesStatus408 ;
79
+ return "408"u8 ;
149
80
case ( int ) HttpStatusCode . Conflict :
150
- return BytesStatus409 ;
81
+ return "409"u8 ;
151
82
case ( int ) HttpStatusCode . Gone :
152
- return BytesStatus410 ;
83
+ return "410"u8 ;
153
84
case ( int ) HttpStatusCode . LengthRequired :
154
- return BytesStatus411 ;
85
+ return "411"u8 ;
155
86
case ( int ) HttpStatusCode . PreconditionFailed :
156
- return BytesStatus412 ;
87
+ return "412"u8 ;
157
88
case ( int ) HttpStatusCode . RequestEntityTooLarge :
158
- return BytesStatus413 ;
89
+ return "413"u8 ;
159
90
case ( int ) HttpStatusCode . RequestUriTooLong :
160
- return BytesStatus414 ;
91
+ return "414"u8 ;
161
92
case ( int ) HttpStatusCode . UnsupportedMediaType :
162
- return BytesStatus415 ;
93
+ return "415"u8 ;
163
94
case ( int ) HttpStatusCode . RequestedRangeNotSatisfiable :
164
- return BytesStatus416 ;
95
+ return "416"u8 ;
165
96
case ( int ) HttpStatusCode . ExpectationFailed :
166
- return BytesStatus417 ;
97
+ return "417"u8 ;
167
98
case ( int ) 418 :
168
- return BytesStatus418 ;
99
+ return "418"u8 ;
169
100
case ( int ) 419 :
170
- return BytesStatus419 ;
101
+ return "419"u8 ;
171
102
case ( int ) HttpStatusCode . MisdirectedRequest :
172
- return BytesStatus421 ;
103
+ return "421"u8 ;
173
104
case ( int ) HttpStatusCode . UnprocessableEntity :
174
- return BytesStatus422 ;
105
+ return "422"u8 ;
175
106
case ( int ) HttpStatusCode . Locked :
176
- return BytesStatus423 ;
107
+ return "423"u8 ;
177
108
case ( int ) HttpStatusCode . FailedDependency :
178
- return BytesStatus424 ;
109
+ return "424"u8 ;
179
110
case ( int ) HttpStatusCode . UpgradeRequired :
180
- return BytesStatus426 ;
111
+ return "426"u8 ;
181
112
case ( int ) HttpStatusCode . PreconditionRequired :
182
- return BytesStatus428 ;
113
+ return "428"u8 ;
183
114
case ( int ) HttpStatusCode . TooManyRequests :
184
- return BytesStatus429 ;
115
+ return "429"u8 ;
185
116
case ( int ) HttpStatusCode . RequestHeaderFieldsTooLarge :
186
- return BytesStatus431 ;
117
+ return "431"u8 ;
187
118
case ( int ) HttpStatusCode . UnavailableForLegalReasons :
188
- return BytesStatus451 ;
119
+ return "451"u8 ;
189
120
190
121
case ( int ) HttpStatusCode . InternalServerError :
191
- return BytesStatus500 ;
122
+ return "500"u8 ;
192
123
case ( int ) HttpStatusCode . NotImplemented :
193
- return BytesStatus501 ;
124
+ return "501"u8 ;
194
125
case ( int ) HttpStatusCode . BadGateway :
195
- return BytesStatus502 ;
126
+ return "502"u8 ;
196
127
case ( int ) HttpStatusCode . ServiceUnavailable :
197
- return BytesStatus503 ;
128
+ return "503"u8 ;
198
129
case ( int ) HttpStatusCode . GatewayTimeout :
199
- return BytesStatus504 ;
130
+ return "504"u8 ;
200
131
case ( int ) HttpStatusCode . HttpVersionNotSupported :
201
- return BytesStatus505 ;
132
+ return "505"u8 ;
202
133
case ( int ) HttpStatusCode . VariantAlsoNegotiates :
203
- return BytesStatus506 ;
134
+ return "506"u8 ;
204
135
case ( int ) HttpStatusCode . InsufficientStorage :
205
- return BytesStatus507 ;
136
+ return "507"u8 ;
206
137
case ( int ) HttpStatusCode . LoopDetected :
207
- return BytesStatus508 ;
138
+ return "508"u8 ;
208
139
case ( int ) HttpStatusCode . NotExtended :
209
- return BytesStatus510 ;
140
+ return "510"u8 ;
210
141
case ( int ) HttpStatusCode . NetworkAuthenticationRequired :
211
- return BytesStatus511 ;
142
+ return "511"u8 ;
212
143
213
144
default :
214
145
return Encoding . ASCII . GetBytes ( statusCode . ToString ( CultureInfo . InvariantCulture ) ) ;
0 commit comments