pub struct Response { /* private fields */ }
Expand description
Represents a parsed HTTP response.
Implementations§
Source§impl Response
impl Response
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance of Response
.
§Returns
Response
- A new response instance with default values.
Sourcepub fn try_get_header<K>(&self, key: K) -> OptionResponseHeadersValuewhere
K: Into<ResponseHeadersKey>,
pub fn try_get_header<K>(&self, key: K) -> OptionResponseHeadersValuewhere
K: Into<ResponseHeadersKey>,
Sourcepub fn try_get_header_front<K>(&self, key: K) -> OptionResponseHeadersValueItemwhere
K: Into<ResponseHeadersKey>,
pub fn try_get_header_front<K>(&self, key: K) -> OptionResponseHeadersValueItemwhere
K: Into<ResponseHeadersKey>,
Sourcepub fn try_get_header_back<K>(&self, key: K) -> OptionResponseHeadersValueItemwhere
K: Into<ResponseHeadersKey>,
pub fn try_get_header_back<K>(&self, key: K) -> OptionResponseHeadersValueItemwhere
K: Into<ResponseHeadersKey>,
Sourcepub fn has_header<K>(&self, key: K) -> boolwhere
K: Into<ResponseHeadersKey>,
pub fn has_header<K>(&self, key: K) -> boolwhere
K: Into<ResponseHeadersKey>,
Sourcepub fn has_header_value<K, V>(&self, key: K, value: V) -> bool
pub fn has_header_value<K, V>(&self, key: K, value: V) -> bool
Sourcepub fn get_headers_length(&self) -> usize
pub fn get_headers_length(&self) -> usize
Sourcepub fn get_header_length<K>(&self, key: K) -> usizewhere
K: Into<ResponseHeadersKey>,
pub fn get_header_length<K>(&self, key: K) -> usizewhere
K: Into<ResponseHeadersKey>,
Sourcepub fn get_headers_values_length(&self) -> usize
pub fn get_headers_values_length(&self) -> usize
Gets the total number of header values in the response.
This counts all values across all headers, so a header with multiple values will contribute more than one to the total count.
§Returns
usize
- The total count of all header values.
Sourcepub fn get_body_string(&self) -> String
pub fn get_body_string(&self) -> String
Retrieves the body content of the response as a UTF-8 encoded string.
This method uses String::from_utf8_lossy
to convert the byte slice returned by self.get_body()
into a string.
If the byte slice contains invalid UTF-8 sequences, they will be replaced with the Unicode replacement character ().
§Returns
String
- The body content as a string.
Sourcepub fn get_body_json<T>(&self) -> ResultJsonError<T>where
T: DeserializeOwned,
pub fn get_body_json<T>(&self) -> ResultJsonError<T>where
T: DeserializeOwned,
Deserializes the body content of the response into a specified type T
.
This method first retrieves the body content as a byte slice using self.get_body()
.
It then attempts to deserialize the byte slice into the specified type T
using json_from_slice
.
§Type Parameters
T
- The target type to deserialize into (must implement DeserializeOwned).
§Returns
ResultJsonError<T>
- The deserialization result.
Sourcepub fn set_header<K, V>(&mut self, key: K, value: V) -> &mut Self
pub fn set_header<K, V>(&mut self, key: K, value: V) -> &mut Self
Sets a header in the response, replacing any existing values.
This function replaces all existing values for a header with a single new value.
§Arguments
K
- The header key (must implement Into). V
- The header value (must implement Into).
§Returns
&mut Self
- A mutable reference to self for chaining.
Sourcepub fn add_header<K, V>(&mut self, key: K, value: V) -> &mut Self
pub fn add_header<K, V>(&mut self, key: K, value: V) -> &mut Self
Adds a header to the response.
This function appends a value to the response headers. If the header already exists, the new value will be added to the existing values.
§Arguments
K
- The header key (must implement Into). V
- The header value (must implement Into).
§Returns
&mut Self
- A mutable reference to self for chaining.
Sourcepub fn remove_header<K>(&mut self, key: K) -> &mut Selfwhere
K: Into<ResponseHeadersKey>,
pub fn remove_header<K>(&mut self, key: K) -> &mut Selfwhere
K: Into<ResponseHeadersKey>,
Sourcepub fn remove_header_value<K, V>(&mut self, key: K, value: V) -> &mut Self
pub fn remove_header_value<K, V>(&mut self, key: K, value: V) -> &mut Self
Removes a specific value from a header in the response.
This function removes only the specified value from the header. If the header has multiple values, only the matching value is removed. If this was the last value for the header, the entire header is removed.
§Arguments
K
- The header key (must implement Into). V
- The value to remove (must implement Into).
§Returns
&mut Self
- A mutable reference to self for chaining.
Sourcepub fn clear_headers(&mut self) -> &mut Self
pub fn clear_headers(&mut self) -> &mut Self
Clears all headers from the response.
This function removes all headers, leaving the headers map empty.
§Returns
&mut Self
- A mutable reference to self for chaining.
Sourcepub fn set_body<T>(&mut self, body: T) -> &mut Selfwhere
T: Into<ResponseBody>,
pub fn set_body<T>(&mut self, body: T) -> &mut Selfwhere
T: Into<ResponseBody>,
Sets the body of the response.
This method allows you to set the body of the response by converting the provided
value into a ResponseBody
type. The body
is updated with the converted value.
§Arguments
T
- The body content (must implement Into).
§Returns
&mut Self
- A mutable reference to self for chaining.
Sourcepub fn set_reason_phrase<T>(&mut self, reason_phrase: T) -> &mut Selfwhere
T: Into<ResponseReasonPhrase>,
pub fn set_reason_phrase<T>(&mut self, reason_phrase: T) -> &mut Selfwhere
T: Into<ResponseReasonPhrase>,
Sets the reason phrase of the response.
This method allows you to set the reason phrase of the response by converting the
provided value into a ResponseReasonPhrase
type. The reason_phrase
is updated
with the converted value.
§Arguments
T
- The reason phrase (must implement Into).
§Returns
&mut Self
- A mutable reference to self for chaining.
Sourcepub fn build(&mut self) -> ResponseData
pub fn build(&mut self) -> ResponseData
Builds the full HTTP response as a byte vector.
This method constructs the complete HTTP response, including the status line, headers, and body. It handles content encoding, content type, connection management, and content length.
§Returns
ResponseData
- The complete HTTP response bytes.
Sourcepub fn get_string(&self) -> String
pub fn get_string(&self) -> String
Converts the response to a formatted string representation.
This method provides a human-readable summary of the response, including its version, status code, reason phrase, headers, and body information.
§Returns
A String
containing formatted response details.
Source§impl Response
impl Response
pub fn get_version(&self) -> &ResponseVersion
pub fn get_mut_version(&mut self) -> &mut ResponseVersion
pub fn set_version(&mut self, val: ResponseVersion) -> &mut Self
pub fn get_status_code(&self) -> &ResponseStatusCode
pub fn get_mut_status_code(&mut self) -> &mut ResponseStatusCode
pub fn set_status_code(&mut self, val: ResponseStatusCode) -> &mut Self
pub fn get_reason_phrase(&self) -> &ResponseReasonPhrase
pub fn get_mut_reason_phrase(&mut self) -> &mut ResponseReasonPhrase
pub fn get_headers(&self) -> &ResponseHeaders
pub fn get_mut_headers(&mut self) -> &mut ResponseHeaders
pub fn get_body(&self) -> &ResponseBody
pub fn get_mut_body(&mut self) -> &mut ResponseBody
Trait Implementations§
Source§impl Default for Response
Provides a default value for Response
.
impl Default for Response
Provides a default value for Response
.
Returns a new Response
instance with all fields initialized to their default values.