Struct HttpResponseText

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

A struct representing an HTTP response.

This struct contains all the components of an HTTP response: the HTTP version, status code, status text, headers, and body. It is used to model and manipulate HTTP responses within the application.

§Fields

  • http_version: A string representing the HTTP version (e.g., “HTTP/1.1”).
  • status_code: The HTTP status code (e.g., 200 for OK, 404 for Not Found).
  • status_text: A string containing the status text associated with the status code (e.g., “OK”, “Not Found”).
  • headers: A HashMap<String, String> containing the headers of the response, where each key is the header name (e.g., “Content-Type”), and the value is the corresponding header value.
  • body: A Vec<u8> representing the body of the HTTP response, which contains the content being returned.

Implementations§

Source§

impl HttpResponseText

Source

pub fn get_http_version(&self) -> HttpVersion

Retrieves the HTTP version associated with this response.

§Returns
  • HttpVersion: The HTTP version (e.g., HTTP/1.1, HTTP/2, etc.) used for the response. Gets the HTTP version of the response.
§Returns
  • HttpVersion - The HTTP version.
Source

pub fn get_status_code(&self) -> ResponseStatusCode

Retrieves the HTTP status code associated with this response.

§Returns
  • ResponseStatusCode: The HTTP status code as a usize (e.g., 200 for OK, 404 for Not Found). Gets the HTTP status code of the response.
§Returns
  • ResponseStatusCode - The status code.
Source

pub fn get_status_text(&self) -> String

Retrieves the status text associated with the HTTP status code.

§Returns
  • String: The human-readable status text (e.g., “OK” for status code 200, “Not Found” for status code 404). Gets the HTTP status text of the response.
§Returns
  • String - The status text.
Source

pub fn get_headers(&self) -> ResponseHeaders

Retrieves the headers of the HTTP response.

§Returns
  • ResponseHeaders: A map of header names and their corresponding values as key-value pairs. Gets the HTTP response headers.
§Returns
  • ResponseHeaders - The response headers.
Source

pub fn get_body(&self) -> RequestBodyString

Retrieves the body content of the HTTP response as a String.

This method attempts to read the body of the response. If the body can be successfully read, it is converted into a String and returned. If reading the body fails, an empty string is returned.

§Returns
  • RequestBodyString: The body of the response as a string. If the body could not be read, an empty string is returned. Gets the HTTP response body.
§Returns
  • RequestBodyString - The response body.

Trait Implementations§

Source§

impl Clone for HttpResponseText

Source§

fn clone(&self) -> HttpResponseText

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 HttpResponseText

Source§

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

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

impl Default for HttpResponseText

Default implementation for HttpResponseText.

§Returns

  • HttpResponseText - Default initialized HttpResponseText.
Source§

fn default() -> Self

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

impl ResponseTrait for HttpResponseText

Implements the ResponseTrait trait for HttpResponseText.

This implementation allows HttpResponseText to convert between text and binary representations of HTTP responses. It provides methods for parsing raw responses, as well as accessing text and binary formats.

§Associated Types

  • OutputText: Specifies the text representation of an HTTP response (HttpResponseText).
  • OutputBinary: Specifies the binary representation of an HTTP response (HttpResponseBinary).
Source§

fn from(response: &[u8]) -> Self::OutputText
where Self: Sized,

Creates a new HttpResponseText from raw response bytes.

§Arguments
  • &[u8] - The raw HTTP response bytes.
§Returns
  • Self::OutputText - The parsed HttpResponseText.
Source§

fn text(&self) -> Self::OutputText

Converts the response to text format.

§Returns
  • Self::OutputText - The text representation of the response.
Source§

fn binary(&self) -> HttpResponseBinary

Converts the response to binary format.

§Returns
  • HttpResponseBinary - The binary representation of the response.
Source§

fn decode(&self, buffer_size: usize) -> HttpResponseBinary

Decodes the response body using the specified buffer size.

§Arguments
  • usize - The buffer size for decoding.
§Returns
  • HttpResponseBinary - The decoded binary response.
Source§

type OutputText = HttpResponseText

Source§

type OutputBinary = HttpResponseBinary

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> Same for T

Source§

type Output = T

Should always be Self
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, 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,

Source§

impl<T> MaybeSendSync for T