pub struct HttpResponse {
pub version: HttpVersion,
pub status_code: ResponseStatusCode,
pub reason_phrase: String,
pub headers: HttpResponseHeaders,
pub body: ResponseBody,
}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.
Fields§
§version: HttpVersionHTTP version (HTTP/1.1, HTTP/2, …).
status_code: ResponseStatusCode3-digit numeric status code (200, 404, …).
reason_phrase: StringReason phrase ("OK", "Not Found", …).
headers: HttpResponseHeadersResponse headers (single-value, lowercase keys).
body: ResponseBodyRaw response body bytes.
Implementations§
Source§impl HttpResponse
impl 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 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 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.