#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct HttpStatus(pub u16);
impl HttpStatus {
pub fn is_redirect(&self) -> bool {
matches!(self.0, 301 | 302 | 303 | 307 | 308)
}
pub fn is_success(&self) -> bool {
(200..300).contains(&self.0)
}
pub fn is_client_error(&self) -> bool {
(400..500).contains(&self.0)
}
pub fn is_server_error(&self) -> bool {
(500..600).contains(&self.0)
}
pub fn reason_phrase(&self) -> &'static str {
match self.0 {
100 => "Continue",
101 => "Switching Protocols",
200 => "OK",
201 => "Created",
204 => "No Content",
301 => "Moved Permanently",
302 => "Found",
303 => "See Other",
304 => "Not Modified",
307 => "Temporary Redirect",
308 => "Permanent Redirect",
400 => "Bad Request",
401 => "Unauthorized",
403 => "Forbidden",
404 => "Not Found",
405 => "Method Not Allowed",
408 => "Request Timeout",
413 => "Payload Too Large",
429 => "Too Many Requests",
500 => "Internal Server Error",
502 => "Bad Gateway",
503 => "Service Unavailable",
504 => "Gateway Timeout",
_ => "",
}
}
}