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
: AHashMap<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
: AVec<u8>
representing the body of the HTTP response, which contains the content being returned.
Implementations§
Source§impl HttpResponseText
impl HttpResponseText
Sourcepub fn get_http_version(&self) -> HttpVersion
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.
Sourcepub fn get_status_code(&self) -> ResponseStatusCode
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).
Sourcepub fn get_status_text(&self) -> String
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).
Sourcepub fn get_headers(&self) -> ResponseHeaders
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.
Sourcepub fn get_body(&self) -> RequestBodyString
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.
Trait Implementations§
Source§impl Clone for HttpResponseText
impl Clone for HttpResponseText
Source§fn clone(&self) -> HttpResponseText
fn clone(&self) -> HttpResponseText
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for HttpResponseText
impl Debug for HttpResponseText
Source§impl Default for HttpResponseText
impl Default for HttpResponseText
Source§impl ResponseTrait for HttpResponseText
Implements the ResponseTrait
trait for HttpResponseText
.
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
).
type OutputText = HttpResponseText
type OutputBinary = HttpResponseBinary
Source§fn from(response: &[u8]) -> Self::OutputTextwhere
Self: Sized,
fn from(response: &[u8]) -> Self::OutputTextwhere
Self: Sized,
Output
. Read more