pub struct Response {
pub version: String,
pub status_code: u16,
pub reason: String,
pub headers: Headers,
pub body: Vec<u8>,
}Expand description
HTTP response.
Fields§
§version: StringHTTP version (e.g., “HTTP/1.1”).
status_code: u16Status code (e.g., 200, 404).
reason: StringReason phrase (e.g., “OK”, “Not Found”).
headers: HeadersResponse headers.
body: Vec<u8>Response body.
Implementations§
Source§impl Response
impl Response
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Check if response indicates success (2xx).
Sourcepub fn is_redirect(&self) -> bool
pub fn is_redirect(&self) -> bool
Check if response indicates redirect (3xx).
Sourcepub fn is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
Check if response indicates client error (4xx).
Sourcepub fn is_server_error(&self) -> bool
pub fn is_server_error(&self) -> bool
Check if response indicates server error (5xx).
Sourcepub fn default_reason(status_code: u16) -> &'static str
pub fn default_reason(status_code: u16) -> &'static str
Get default reason phrase for status code.
Sourcepub fn content_length(&self) -> Option<usize>
pub fn content_length(&self) -> Option<usize>
Get Content-Length.
Sourcepub fn is_chunked(&self) -> bool
pub fn is_chunked(&self) -> bool
Check if response has chunked transfer encoding.
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
Get Content-Type.
Sourcepub fn parse(data: &[u8]) -> Result<(Self, usize)>
pub fn parse(data: &[u8]) -> Result<(Self, usize)>
Parse a complete HTTP response from raw bytes.
Returns the parsed response and the total bytes consumed.
Sourcefn parse_status_line(line: &str) -> Result<(String, u16, String)>
fn parse_status_line(line: &str) -> Result<(String, u16, String)>
Parse status line: “HTTP/1.1 200 OK”
Sourcepub fn parse_headers_only(data: &[u8]) -> Result<(Self, usize)>
pub fn parse_headers_only(data: &[u8]) -> Result<(Self, usize)>
Parse headers only, without body.
Useful for HEAD responses or when body will be streamed separately.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more