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_informational(&self) -> bool
pub fn is_informational(&self) -> bool
Was the response a 1xx informational status?
§Returns
bool-truewhen the status code lies in the100..200range.
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.
Sourcepub fn error_for_status(self) -> Result<Self, RequestError>
pub fn error_for_status(self) -> Result<Self, RequestError>
Converts a 4xx or 5xx HTTP response into an error while returning 1xx–3xx responses unchanged.
§Returns
Result<Self, RequestError>-Ok(self)for status codes< 400, orErr(RequestError)otherwise.
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
Returns the Content-Type response header value when present.
§Returns
Option<&str>-Content-Typeheader value, if present.
Sourcepub fn content_length(&self) -> Option<usize>
pub fn content_length(&self) -> Option<usize>
Returns the parsed decimal Content-Length header value when present and valid.
§Returns
Option<usize>- Declared byte length, if present and valid.
Sourcepub fn location(&self) -> Option<&str>
pub fn location(&self) -> Option<&str>
Returns the Location response header value when present.
§Returns
Option<&str>- Redirect or created-resourceLocationheader, if present.
Sourcepub fn text_strict(&self) -> Result<&str, Utf8Error>
pub fn text_strict(&self) -> Result<&str, Utf8Error>
Borrows the response body as a strict UTF-8 &str without allocating.
§Returns
Result<&str, Utf8Error>- Borrowed UTF-8 body text or decoding error.
Returns all raw Set-Cookie header lines received on this response.
§Returns
Vec<&str>- Every individualSet-Cookieheader value in arrival order.
Parses all cookies declared by one or more Set-Cookie headers, 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.