http/
status.rs

1pub trait StatusCode {
2    /// Returns true if the status code of the
3    /// request represents an OK status (200-300)
4    fn is_http_ok(&self) -> bool;
5    /// Returns true if the status code of the
6    /// request doesn't represent an OK status (200-300)
7    fn is_http_err(&self) -> bool;
8    /// Get a human-readable description of the request's status code
9    fn status_msg(&self) -> &'static str;
10}
11
12impl StatusCode for u16 {
13    #[inline]
14    fn is_http_ok(&self) -> bool {
15        (200..300).contains(self)
16    }
17    #[inline]
18    fn is_http_err(&self) -> bool {
19        !self.is_http_ok()
20    }
21    fn status_msg(&self) -> &'static str {
22        match self {
23            200 => "OK",
24            201 => "CREATED",
25            202 => "ACCEPTED",
26            203 => "NON-AUTHORITATIVE INFORMATION",
27            204 => "NO CONTENT",
28            205 => "RESET CONTENT",
29            206 => "PARTIAL CONTENT",
30            300 => "MULTIPLE CHOICES",
31            301 => "MOVED PERMANENTLY",
32            302 => "FOUND",
33            303 => "SEE OTHER",
34            304 => "NOT MODIFIED",
35            307 => "TEMPORARY REDIRECT",
36            308 => "PERMANENT REDIRECT",
37            400 => "BAD REQUEST",
38            401 => "UNAUTHORIZED",
39            403 => "FORBIDDEN",
40            404 => "NOT FOUND",
41            405 => "METHOD NOT ALLOWED",
42            406 => "NOT ACCEPTABLE",
43            407 => "PROXY AUTHENTICATION REQUIRED",
44            408 => "REQUEST TIMEOUT",
45            409 => "CONFLICT",
46            410 => "GONE",
47            411 => "LENGTH REQUIRED",
48            412 => "PRECONDITION FAILED",
49            413 => "PAYLOAD TOO LARGE",
50            414 => "URI TOO LONG",
51            415 => "UNSUPPORTED MEDIA TYPE",
52            416 => "REQUESTED RANGE NOT SATISFIABLE",
53            429 => "TOO MANY REQUESTS",
54            501 => "NOT IMPLEMENTED",
55            500 => "INTERNAL SERVER ERROR",
56            _ => "?",
57        }
58    }
59}