coman/core/
http_response.rs1#[derive(Debug, Clone)]
3pub struct HttpResponse {
4 pub version: String,
6 pub status: u16,
8 pub status_text: String,
10 pub headers: Vec<(String, String)>,
12 pub body: String,
14 pub elapsed_ms: u128,
18 pub url: String,
20}
21
22impl HttpResponse {
23 pub fn is_success(&self) -> bool {
25 (200..300).contains(&self.status)
26 }
27
28 pub fn is_redirect(&self) -> bool {
30 (300..400).contains(&self.status)
31 }
32
33 pub fn is_client_error(&self) -> bool {
35 (400..500).contains(&self.status)
36 }
37
38 pub fn is_server_error(&self) -> bool {
40 (500..600).contains(&self.status)
41 }
42
43 pub fn json<T: serde::de::DeserializeOwned>(&self) -> Result<T, serde_json::Error> {
45 serde_json::from_str(&self.body)
46 }
47}