@@ -16,7 +16,7 @@ pub enum StatusCode {
16
16
///
17
17
/// This code is sent in response to an Upgrade request header from the client, and
18
18
/// indicates the protocol the server is switching to.
19
- SwitchingProtocol = 101 ,
19
+ SwitchingProtocols = 101 ,
20
20
21
21
/// 103 Early Hints
22
22
///
@@ -101,7 +101,7 @@ pub enum StatusCode {
101
101
/// URI with a GET request.
102
102
SeeOther = 303 ,
103
103
104
- /// 304 Modified
104
+ /// 304 Not Modified
105
105
///
106
106
/// This is used for caching purposes. It tells the client that the response has not been
107
107
/// modified, so the client can continue to use the same cached version of the response.
@@ -257,7 +257,7 @@ pub enum StatusCode {
257
257
/// The request was directed at a server that is not able to produce a response. This can be
258
258
/// sent by a server that is not configured to produce responses for the combination of scheme
259
259
/// and authority that are included in the request URI.
260
- MisDirectedRequest = 421 ,
260
+ MisdirectedRequest = 421 ,
261
261
262
262
/// 425 Too Early
263
263
///
@@ -334,7 +334,7 @@ pub enum StatusCode {
334
334
/// 505 HTTP Version Not Supported
335
335
///
336
336
/// The HTTP version used in the request is not supported by the server.
337
- VersionNotSupported = 505 ,
337
+ HttpVersionNotSupported = 505 ,
338
338
339
339
/// 506 Variant Also Negotiates
340
340
///
@@ -358,8 +358,59 @@ impl StatusCode {
358
358
/// The canonical reason for a given status code
359
359
pub fn canonical_reason ( & self ) -> & ' static str {
360
360
match self {
361
- StatusCode :: Ok => "OK" ,
362
- _ => unimplemented ! ( ) ,
361
+ StatusCode :: Continue => "Continue" ,
362
+ StatusCode :: SwitchingProtocols => "Switching Protocols" ,
363
+ StatusCode :: EarlyHints => "Early Hints" ,
364
+ StatusCode :: Ok => "Ok" ,
365
+ StatusCode :: Created => "Created" ,
366
+ StatusCode :: Accepted => "Accepted" ,
367
+ StatusCode :: NonAuthoritativeInformation => "Non Authoritative Information" ,
368
+ StatusCode :: NoContent => "No Content" ,
369
+ StatusCode :: ResetContent => "Reset Content" ,
370
+ StatusCode :: PartialContent => "Partial Content" ,
371
+ StatusCode :: ImUsed => "Im Used" ,
372
+ StatusCode :: MultipleChoice => "Multiple Choice" ,
373
+ StatusCode :: MovedPermanently => "Moved Permanently" ,
374
+ StatusCode :: Found => "Found" ,
375
+ StatusCode :: SeeOther => "See Other" ,
376
+ StatusCode :: NotModified => "Modified" ,
377
+ StatusCode :: TemporaryRedirect => "Temporary Redirect" ,
378
+ StatusCode :: PermanentRedirect => "Permanent Redirect" ,
379
+ StatusCode :: BadRequest => "Bad Request" ,
380
+ StatusCode :: Unauthorized => "Unauthorized" ,
381
+ StatusCode :: PaymentRequired => "Payment Required" ,
382
+ StatusCode :: Forbidden => "Forbidden" ,
383
+ StatusCode :: NotFound => "Not Found" ,
384
+ StatusCode :: MethodNotAllowed => "Method Not Allowed" ,
385
+ StatusCode :: NotAcceptable => "Not Acceptable" ,
386
+ StatusCode :: ProxyAuthenticationRequired => "Proxy Authentication Required" ,
387
+ StatusCode :: RequestTimeout => "Request Timeout" ,
388
+ StatusCode :: Conflict => "Conflict" ,
389
+ StatusCode :: Gone => "Gone" ,
390
+ StatusCode :: LengthRequired => "Length Required" ,
391
+ StatusCode :: PreconditionFailed => "Precondition Failed" ,
392
+ StatusCode :: PayloadTooLarge => "Payload Too Large" ,
393
+ StatusCode :: UriTooLong => "URI Too Long" ,
394
+ StatusCode :: UnsupportedMediaType => "Unsupported Media Type" ,
395
+ StatusCode :: RequestedRangeNotSatisfiable => "Requested Range Not Satisfiable" ,
396
+ StatusCode :: ExpectationFailed => "Expectation Failed" ,
397
+ StatusCode :: ImATeapot => "I'm a teapot" ,
398
+ StatusCode :: MisdirectedRequest => "Misdirected Request" ,
399
+ StatusCode :: TooEarly => "Too Early" ,
400
+ StatusCode :: UpgradeRequired => "Upgrade Required" ,
401
+ StatusCode :: PreconditionRequired => "Precondition Required" ,
402
+ StatusCode :: TooManyRequests => "Too Many Requests" ,
403
+ StatusCode :: RequestHeaderFieldsTooLarge => "Request Header Fields Too Large" ,
404
+ StatusCode :: UnavailableForLegalReasons => "Unavailable For Legal Reasons" ,
405
+ StatusCode :: InternalServerError => "Internal Server Error" ,
406
+ StatusCode :: NotImplemented => "Not Implemented" ,
407
+ StatusCode :: BadGateway => "Bad Gateway" ,
408
+ StatusCode :: ServiceUnavailable => "Service Unavailable" ,
409
+ StatusCode :: GatewayTimeout => "Gateway Timeout" ,
410
+ StatusCode :: HttpVersionNotSupported => "HTTP Version Not Supported" ,
411
+ StatusCode :: VariantAlsoNegotiates => "Variant Also Negotiates" ,
412
+ StatusCode :: NotExtended => "Not Extended" ,
413
+ StatusCode :: NetworkAuthenticationRequired => "Network Authentication Required" ,
363
414
}
364
415
}
365
416
}
@@ -372,10 +423,63 @@ impl Into<u16> for StatusCode {
372
423
373
424
impl std:: convert:: TryFrom < u16 > for StatusCode {
374
425
type Error = Box < dyn std:: error:: Error + Send + Sync + ' static > ;
426
+
375
427
fn try_from ( value : u16 ) -> Result < Self , Self :: Error > {
376
428
match value {
429
+ 100 => Ok ( StatusCode :: Continue ) ,
430
+ 101 => Ok ( StatusCode :: SwitchingProtocols ) ,
431
+ 103 => Ok ( StatusCode :: EarlyHints ) ,
377
432
200 => Ok ( StatusCode :: Ok ) ,
378
- _ => unimplemented ! ( ) ,
433
+ 201 => Ok ( StatusCode :: Created ) ,
434
+ 202 => Ok ( StatusCode :: Accepted ) ,
435
+ 203 => Ok ( StatusCode :: NonAuthoritativeInformation ) ,
436
+ 204 => Ok ( StatusCode :: NoContent ) ,
437
+ 205 => Ok ( StatusCode :: ResetContent ) ,
438
+ 206 => Ok ( StatusCode :: PartialContent ) ,
439
+ 226 => Ok ( StatusCode :: ImUsed ) ,
440
+ 300 => Ok ( StatusCode :: MultipleChoice ) ,
441
+ 301 => Ok ( StatusCode :: MovedPermanently ) ,
442
+ 302 => Ok ( StatusCode :: Found ) ,
443
+ 303 => Ok ( StatusCode :: SeeOther ) ,
444
+ 304 => Ok ( StatusCode :: NotModified ) ,
445
+ 307 => Ok ( StatusCode :: TemporaryRedirect ) ,
446
+ 308 => Ok ( StatusCode :: PermanentRedirect ) ,
447
+ 400 => Ok ( StatusCode :: BadRequest ) ,
448
+ 401 => Ok ( StatusCode :: Unauthorized ) ,
449
+ 402 => Ok ( StatusCode :: PaymentRequired ) ,
450
+ 403 => Ok ( StatusCode :: Forbidden ) ,
451
+ 404 => Ok ( StatusCode :: NotFound ) ,
452
+ 405 => Ok ( StatusCode :: MethodNotAllowed ) ,
453
+ 406 => Ok ( StatusCode :: NotAcceptable ) ,
454
+ 407 => Ok ( StatusCode :: ProxyAuthenticationRequired ) ,
455
+ 408 => Ok ( StatusCode :: RequestTimeout ) ,
456
+ 409 => Ok ( StatusCode :: Conflict ) ,
457
+ 410 => Ok ( StatusCode :: Gone ) ,
458
+ 411 => Ok ( StatusCode :: LengthRequired ) ,
459
+ 412 => Ok ( StatusCode :: PreconditionFailed ) ,
460
+ 413 => Ok ( StatusCode :: PayloadTooLarge ) ,
461
+ 414 => Ok ( StatusCode :: UriTooLong ) ,
462
+ 415 => Ok ( StatusCode :: UnsupportedMediaType ) ,
463
+ 416 => Ok ( StatusCode :: RequestedRangeNotSatisfiable ) ,
464
+ 417 => Ok ( StatusCode :: ExpectationFailed ) ,
465
+ 418 => Ok ( StatusCode :: ImATeapot ) ,
466
+ 421 => Ok ( StatusCode :: MisdirectedRequest ) ,
467
+ 425 => Ok ( StatusCode :: TooEarly ) ,
468
+ 426 => Ok ( StatusCode :: UpgradeRequired ) ,
469
+ 428 => Ok ( StatusCode :: PreconditionRequired ) ,
470
+ 429 => Ok ( StatusCode :: TooManyRequests ) ,
471
+ 431 => Ok ( StatusCode :: RequestHeaderFieldsTooLarge ) ,
472
+ 451 => Ok ( StatusCode :: UnavailableForLegalReasons ) ,
473
+ 500 => Ok ( StatusCode :: InternalServerError ) ,
474
+ 501 => Ok ( StatusCode :: NotImplemented ) ,
475
+ 502 => Ok ( StatusCode :: BadGateway ) ,
476
+ 503 => Ok ( StatusCode :: ServiceUnavailable ) ,
477
+ 504 => Ok ( StatusCode :: GatewayTimeout ) ,
478
+ 505 => Ok ( StatusCode :: HttpVersionNotSupported ) ,
479
+ 506 => Ok ( StatusCode :: VariantAlsoNegotiates ) ,
480
+ 510 => Ok ( StatusCode :: NotExtended ) ,
481
+ 511 => Ok ( StatusCode :: NetworkAuthenticationRequired ) ,
482
+ _ => unimplemented ! ( ) , // TODO: return parser error
379
483
}
380
484
}
381
485
}
0 commit comments