pub struct HttpResponse { /* private fields */ }Expand description
Parsed HTTP response.
Value type with all fields public — no Arc<RwLock> wrapping, no
associated-type / boxed-trait indirection. Use the field accessors
directly (response.status_code, response.body, …) or the
convenience helpers (response.text(), response.is_success()).
HttpResponse is Clone and Debug. Decoding is a method
(HttpResponse::decode) that returns a fresh HttpResponse with
the body expanded — original is untouched.
Implementations§
Source§impl HttpResponse
Inherent implementation of HttpResponse.
impl HttpResponse
Inherent implementation of HttpResponse.
Sourcepub fn from_bytes(response: &[u8]) -> Self
pub fn from_bytes(response: &[u8]) -> Self
Construct from raw response bytes (status line + headers + body).
§Arguments
&[u8]- The complete raw response bytes, including the status line, the header block, and the body.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Was the response a 2xx success?
§Returns
bool-truewhen the status code lies in the200..300range.
Sourcepub fn is_redirect(&self) -> bool
pub fn is_redirect(&self) -> bool
Was the response a 3xx redirect?
§Returns
bool-truewhen the status code lies in the300..400range.
Sourcepub fn is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
Was the response a 4xx client error?
§Returns
bool-truewhen the status code lies in the400..500range.
Sourcepub fn is_server_error(&self) -> bool
pub fn is_server_error(&self) -> bool
Was the response a 5xx server error?
§Returns
bool-truewhen the status code lies in the500..600range.
Sourcepub fn get_header<K>(&self, key: K) -> Option<&str>
pub fn get_header<K>(&self, key: K) -> Option<&str>
Sourcepub fn text(&self) -> String
pub fn text(&self) -> String
Get the response body as a UTF-8 string (lossy on invalid bytes).
§Returns
String- The owned body text, with invalid byte sequences replaced.
Sourcepub fn json<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
pub fn json<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
Deserialize the response body from JSON into T.
§Returns
Result<T, serde_json::Error>- Parsed JSON payload or a deserialization error.
Parses cookies declared by the response’s Set-Cookie header, when present.
§Returns
Option<HashMapXxHash3_64<String, String>>- Parsed cookie map, orNonewhenSet-Cookieis absent.
Sourcepub fn decode(&self, buffer_size: usize) -> HttpResponse
pub fn decode(&self, buffer_size: usize) -> HttpResponse
Decode the body using the headers’ Content-Encoding (gzip / deflate /
br). Returns a fresh response with the decoded body — the original is
untouched. buffer_size controls the chunk size for streaming decoders.
§Arguments
usize- The chunk size used by the streaming decoders.
§Returns
HttpResponse- A new response identical to this one except that its body holds the decoded bytes.
Source§impl HttpResponse
impl HttpResponse
pub fn get_version(&self) -> &HttpVersion
pub fn get_status_code(&self) -> usize
pub fn get_reason_phrase(&self) -> &String
pub fn get_headers(&self) -> &HashMapXxHash3_64<String, String>
pub fn get_body(&self) -> &Vec<u8> ⓘ
Source§impl HttpResponse
impl HttpResponse
pub fn set_version(&mut self, val: HttpVersion) -> &mut Self
pub fn set_status_code(&mut self, val: usize) -> &mut Self
pub fn set_reason_phrase(&mut self, val: impl AsRef<str>) -> &mut Self
pub fn set_headers( &mut self, val: HashMapXxHash3_64<String, String>, ) -> &mut Self
pub fn set_body(&mut self, val: impl AsRef<[u8]>) -> &mut Self
Trait Implementations§
Source§impl Clone for HttpResponse
impl Clone for HttpResponse
Source§impl Debug for HttpResponse
impl Debug for HttpResponse
Source§impl Default for HttpResponse
Default construction for HttpResponse.
impl Default for HttpResponse
Default construction for HttpResponse.