crane_webserver/
status.rs1#![allow(non_camel_case_types)]
2
3#[repr(u32)]
5#[derive(Debug, Clone, Copy)]
6pub enum HttpStatus {
7 Continue = 100,
8 Switching_Protocols = 101,
9 OK = 200,
10 Created = 201,
11 Accepted = 202,
12 Non_Authoritative_Information = 203,
13 No_Content = 204,
14 Reset_Content = 205,
15 Partial_Content = 206,
16 Multiple_Choices = 300,
17 Moved_Permanently = 301,
18 Found = 302,
19 See_Other = 303,
20 Not_Modified = 304,
21 Use_Proxy = 305,
22 Temporary_Redirect = 307,
23 Permanent_Redirect = 308,
24 Bad_Request = 400,
25 Unauthorized = 401,
26 Payment_Required = 402,
27 Forbidden = 403,
28 Not_Found = 404,
29 Method_Not_Allowed = 405,
30 Not_Acceptable = 406,
31 Proxy_Authentication_Required = 407,
32 Request_Timeout = 408,
33 Conflict = 409,
34 Gone = 410,
35 Length_Required = 411,
36 Precondition_Failed = 412,
37 Payload_Too_Large = 413,
38 URI_Too_Long = 414,
39 Unsupported_Media_Type = 415,
40 Range_Not_Satisfiable = 416,
41 Expectation_Failed = 417,
42 Im_A_Teapot = 418,
43 Misdirected_Request = 421,
44 Unprocessable_Entity = 422,
45 Locked = 423,
46 Failed_Dependency = 424,
47 Too_Early = 425,
48 Upgrade_Required = 426,
49 Precondition_Required = 428,
50 Too_Many_Requests = 429,
51 Request_Header_Fields_Too_Large = 431,
52 Unavailable_For_Legal_Reasons = 451,
53 Internal_Server_Error = 500,
54 Not_Implemented = 501,
55 Bad_Gateway = 502,
56 Service_Unavailable = 503,
57 Gateway_Timeout = 504,
58 HTTP_Version_Not_Supported = 505,
59 Variant_Also_Negotiates = 506,
60 Insufficient_Storage = 507,
61 Loop_Detected = 508,
62 Not_Extended = 510,
63 Network_Authentication_Required = 511,
64}
65
66impl HttpStatus {
67 pub fn get_string(&self) -> String {
68 let status_name = self.to_string();
69 let code = *self as u32;
70 format!("{code} {status_name}")
71 }
72}
73
74impl std::fmt::Display for HttpStatus {
75 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76 let s = format!("{self:?}").replace("_", " ");
77 write!(f, "{}", s)
78 }
79}