Response

Struct Response 

Source
pub struct Response { /* private fields */ }
Expand description

Represents a parsed HTTP response.

Implementations§

Source§

impl Response

Source

pub fn new() -> Response

Creates a new instance of Response.

§Returns
  • Response - A new response instance with default values.
Source

pub fn try_get_header<K>(&self, key: K) -> Option<VecDeque<String>>
where K: AsRef<str>,

Retrieves the value of a response header by its key.

§Arguments
  • AsRef<str> - The header’s key (must implement AsRef).
§Returns
  • OptionResponseHeadersValue - The optional header values.
Source

pub fn try_get_header_front<K>(&self, key: K) -> Option<String>
where K: AsRef<str>,

Retrieves the first value of a response header by its key.

§Arguments
  • AsRef<str> - The header’s key (must implement AsRef).
§Returns
  • OptionResponseHeadersValueItem - The first header value if exists.
Source

pub fn try_get_header_back<K>(&self, key: K) -> Option<String>
where K: AsRef<str>,

Retrieves the last value of a response header by its key.

§Arguments
  • AsRef<str> - The header’s key (must implement AsRef).
§Returns
  • OptionResponseHeadersValueItem - The last header value if exists.
Source

pub fn has_header<K>(&self, key: K) -> bool
where K: AsRef<str>,

Checks if a header exists in the response.

§Arguments
  • AsRef<str> - The header key to check (must implement AsRef).
§Returns
  • bool - Whether the header exists.
Source

pub fn has_header_value<K, V>(&self, key: K, value: V) -> bool
where K: AsRef<str>, V: AsRef<str>,

Checks if a header contains a specific value.

§Arguments
  • AsRef<str> - The header key to check (must implement AsRef).
  • AsRef<str> - The value to search for (must implement AsRef).
§Returns
  • bool - Whether the header contains the value.
Source

pub fn get_headers_length(&self) -> usize

Gets the number of headers in the response.

§Returns
  • usize - The count of unique header keys.
Source

pub fn get_header_length<K>(&self, key: K) -> usize
where K: AsRef<str>,

Gets the number of values for a specific header key.

§Arguments
  • AsRef<str> - The header key to count (must implement AsRef).
§Returns
  • usize - The count of values for the header.
Source

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.
Source

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() as_ref 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.
Source

pub fn get_body_json<T>(&self) -> Result<T, Error>

Deserializes the body content of the response as_ref 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 as_ref the specified type T using json_from_slice.

§Arguments
  • DeserializeOwned - The target type to deserialize as_ref (must implement DeserializeOwned).
§Returns
  • ResultJsonError<T> - The deserialization result.
Source

pub fn set_header<K, V>(&mut self, key: K, value: V) -> &mut Response
where K: AsRef<str>, V: AsRef<str>,

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
  • AsRef<str> - The header key (must implement AsRef).
  • AsRef<str> - The header value (must implement AsRef).
§Returns
  • &mut Self - A mutable reference to self for chaining.
Source

pub fn add_header<K, V>(&mut self, key: K, value: V) -> &mut Response
where K: AsRef<str>, V: AsRef<str>,

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
  • AsRef<str> - The header key (must implement AsRef).
  • AsRef<str> - The header value (must implement AsRef).
§Returns
  • &mut Self - A mutable reference to self for chaining.
Source

pub fn remove_header<K>(&mut self, key: K) -> &mut Response
where K: AsRef<str>,

Removes a header from the response.

This function removes all values for the specified header key.

§Arguments
  • AsRef<str> - The header key to remove (must implement AsRef).
§Returns
  • &mut Self - A mutable reference to self for chaining.
Source

pub fn remove_header_value<K, V>(&mut self, key: K, value: V) -> &mut Response
where K: AsRef<str>, V: AsRef<str>,

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
  • AsRef<str> - The header key (must implement AsRef).
  • AsRef<str> - The value to remove (must implement AsRef).
§Returns
  • &mut Self - A mutable reference to self for chaining.
Source

pub fn clear_headers(&mut self) -> &mut Response

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.
Source

pub fn set_body<T>(&mut self, body: T) -> &mut Response
where T: AsRef<[u8]>,

Sets the body of the response.

This method allows you to set the body of the response by converting the provided value as_ref a ResponseBody type. The body is updated with the converted value.

§Arguments
  • AsRef<[u8]> - The body content (must implement AsRef<u8>).
§Returns
  • &mut Self - A mutable reference to self for chaining.
Source

pub fn set_reason_phrase<T>(&mut self, reason_phrase: T) -> &mut Response
where T: AsRef<str>,

Sets the reason phrase of the response.

This method allows you to set the reason phrase of the response by converting the provided value as_ref a ResponseReasonPhrase type. The reason_phrase is updated with the converted value.

§Arguments
  • AsRef<str> - The reason phrase (must implement AsRef).
§Returns
  • &mut Self - A mutable reference to self for chaining.
Source

pub fn build(&mut self) -> Vec<u8>

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.
Source

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

Source

pub fn get_version(&self) -> &HttpVersion

Source

pub fn get_mut_version(&mut self) -> &mut HttpVersion

Source

pub fn set_version(&mut self, val: HttpVersion) -> &mut Response

Source

pub fn get_status_code(&self) -> &usize

Source

pub fn get_mut_status_code(&mut self) -> &mut usize

Source

pub fn set_status_code(&mut self, val: usize) -> &mut Response

Source

pub fn get_reason_phrase(&self) -> &String

Source

pub fn get_mut_reason_phrase(&mut self) -> &mut String

Source

pub fn get_headers( &self, ) -> &HashMap<String, VecDeque<String>, BuildHasherDefault<Hasher>>

Source

pub fn get_mut_headers( &mut self, ) -> &mut HashMap<String, VecDeque<String>, BuildHasherDefault<Hasher>>

Source

pub fn get_body(&self) -> &Vec<u8>

Source

pub fn get_mut_body(&mut self) -> &mut Vec<u8>

Trait Implementations§

Source§

impl Clone for Response

Source§

fn clone(&self) -> Response

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Response

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Response

Provides a default value for Response.

Returns a new Response instance with all fields initialized to their default values.

Source§

fn default() -> Response

Returns the “default value” for a type. Read more
Source§

impl Display for Response

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Response

Source§

fn eq(&self, other: &Response) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Response

Source§

impl StructuralPartialEq for Response

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> AnySend for T
where T: Any + Send,

Source§

impl<T> AnySendClone for T
where T: Any + Send + Clone,

Source§

impl<T> AnySendSync for T
where T: Any + Send + Sync,

Source§

impl<T> AnySendSyncClone for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> AnySync for T
where T: Any + Sync,

Source§

impl<T> AnySyncClone for T
where T: Any + Sync + Clone,

Source§

impl<T> ErasedDestructor for T
where T: 'static,