1use std::fmt::Display;
2
3pub enum StatusCode {
4 Ok = 200,
5 Created = 201,
6 Accepted = 202,
7 NonAuthoritativeInformation = 203,
8 NoContent = 204,
9 ResetContent = 205,
10 PartialContent = 206,
11
12 MultipleChoices = 300,
13 MovedPermanently = 301,
14 Found = 302,
15 SeeOther = 303,
16 NotModified = 304,
17 UseProxy = 305,
18 TemporaryRedirect = 307,
19 PermanentRedirect = 308,
20
21 BadRequest = 400,
22 UnAuthorized = 401,
23 PaymentRequired = 402,
24 Forbidden = 403,
25 NotFound = 404,
26 MethodNotAllowed = 405,
27 NotAcceptable = 406,
28 ProxyAuthenticationRequired = 407,
29 RequestTimeout = 408,
30 Conflict = 409,
31 Gone = 410,
32 LengthRequired = 411,
33 PreconditionFailed = 412,
34 PayloadTooLarge = 413,
35 UriTooLong = 414,
36 UnsupportedMediaType = 415,
37 RangeNotSatisfiable = 416,
38 ExpectationFailed = 417,
39 ImATeapot = 418,
40 UnprocessableEntity = 422,
41 TooManyRequests = 429,
42
43 InternalServerError = 500,
44 NotImplemented = 501,
45 BadGateway = 502,
46 ServiceUnavailable = 503,
47 GatewayTimeout = 504,
48 HttpVersionNotSupported = 505,
49 InsufficientStorage = 507,
50 LoopDetected = 508,
51}
52
53impl Display for StatusCode {
54 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55 let str = match self {
56 StatusCode::Ok => "200 OK".to_string(),
57 StatusCode::Created => "201 Created".to_string(),
58 StatusCode::Accepted => "202 Accepted".to_string(),
59 StatusCode::NonAuthoritativeInformation => {
60 "203 Non-Authoritative Information".to_string()
61 }
62 StatusCode::NoContent => "204 No Content".to_string(),
63 StatusCode::ResetContent => "205 Reset Content".to_string(),
64 StatusCode::PartialContent => "206 Partial Content".to_string(),
65
66 StatusCode::MultipleChoices => "300 Multiple Choices".to_string(),
67 StatusCode::MovedPermanently => "301 Moved Permanently".to_string(),
68 StatusCode::Found => "302 Found".to_string(),
69 StatusCode::SeeOther => "303 See Other".to_string(),
70 StatusCode::NotModified => "304 Not Modified".to_string(),
71 StatusCode::UseProxy => "305 Use Proxy".to_string(),
72 StatusCode::TemporaryRedirect => "307 Temporary Redirect".to_string(),
73 StatusCode::PermanentRedirect => "308 Permanent Redirect".to_string(),
74
75 StatusCode::BadRequest => "400 Bad Request".to_string(),
76 StatusCode::UnAuthorized => "401 Unauthorized".to_string(),
77 StatusCode::PaymentRequired => "402 Payment Required".to_string(),
78 StatusCode::Forbidden => "403 Forbidden".to_string(),
79 StatusCode::NotFound => "404 Not Found".to_string(),
80 StatusCode::MethodNotAllowed => "405 Method Not Allowed".to_string(),
81 StatusCode::NotAcceptable => "406 Not Acceptable".to_string(),
82 StatusCode::ProxyAuthenticationRequired => {
83 "407 Proxy Authentication Required".to_string()
84 }
85 StatusCode::RequestTimeout => "408 Request Timeout".to_string(),
86 StatusCode::Conflict => "409 Conflict".to_string(),
87 StatusCode::Gone => "410 Gone".to_string(),
88 StatusCode::LengthRequired => "411 Length Required".to_string(),
89 StatusCode::PreconditionFailed => "412 Precondition Failed".to_string(),
90 StatusCode::PayloadTooLarge => "413 Payload Too Large".to_string(),
91 StatusCode::UriTooLong => "414 URI Too Long".to_string(),
92 StatusCode::UnsupportedMediaType => "415 Unsupported Media Type".to_string(),
93 StatusCode::RangeNotSatisfiable => "416 Range Not Satisfiable".to_string(),
94 StatusCode::ExpectationFailed => "417 Expectation Failed".to_string(),
95 StatusCode::ImATeapot => "418 I'm a teapot".to_string(),
96 StatusCode::UnprocessableEntity => "422 Unprocessable Entity".to_string(),
97 StatusCode::TooManyRequests => "429 Too Many Requests".to_string(),
98
99 StatusCode::InternalServerError => "500 Internal Server Error".to_string(),
100 StatusCode::NotImplemented => "501 Not Implemented".to_string(),
101 StatusCode::BadGateway => "502 Bad Gateway".to_string(),
102 StatusCode::ServiceUnavailable => "503 Service Unavailable".to_string(),
103 StatusCode::GatewayTimeout => "504 Gateway Timeout".to_string(),
104 StatusCode::HttpVersionNotSupported => "505 HTTP Version Not Supported".to_string(),
105 StatusCode::InsufficientStorage => "507 Insufficient Storage".to_string(),
106 StatusCode::LoopDetected => "508 Loop Detected".to_string(),
107 };
108 write!(f, "{}", str)
109 }
110}