pub struct Response { /* private fields */ }Expand description
Represents an HTTP response.
§Fields
version: The HTTP version of the response.status_code: The status code of the response.reason_phrase: The reason phrase corresponding to the status code.headers: A collection of HTTP headers as key-value pairs.body: The binary body of the response.
Implementations§
Source§impl Response
impl Response
Sourcepub fn get_header<K>(&self, key: K) -> Option<ResponseHeadersValue>where
K: Into<ResponseHeadersKey>,
pub fn get_header<K>(&self, key: K) -> Option<ResponseHeadersValue>where
K: Into<ResponseHeadersKey>,
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
Adds a header to the response.
This function inserts a key-value pair into the response headers.
The key and value are converted into ResponseHeadersKey, allowing for efficient handling of both owned and borrowed string data.
§Parameters
key: The header key, which will be converted into aResponseHeadersKey.value: The value of the header, which will be converted into aResponseHeadersValue.
§Returns
- Returns a mutable reference to the current instance (
&mut Self), allowing for method chaining.
Sourcepub fn set_body<T: Into<ResponseBody>>(&mut self, body: T) -> &mut Self
pub fn set_body<T: Into<ResponseBody>>(&mut self, body: T) -> &mut Self
Set 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,
and the method returns a mutable reference to the current instance for method chaining.
§Parameters
body: The body of the response to be set. It can be any type that can be converted into aResponseBodyusing theIntotrait.
§Return Value
- Returns a mutable reference to the current instance of the struct, enabling method chaining. Set 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,
and the method returns a mutable reference to the current instance for method chaining.
§Parameters
body: The body of the response to be set. It can be any type that can be converted into aResponseBodyusing theIntotrait.
§Return Value
- Returns a mutable reference to the current instance of the struct, enabling method chaining.
Sourcepub fn set_reason_phrase<T: Into<ResponseReasonPhrase>>(
&mut self,
reason_phrase: T,
) -> &mut Self
pub fn set_reason_phrase<T: Into<ResponseReasonPhrase>>( &mut self, reason_phrase: T, ) -> &mut Self
Set 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, and the method returns a mutable reference to the current
instance for method chaining.
§Parameters
reason_phrase: The reason phrase to be set for the response. It can be any type that can be converted into aResponseReasonPhraseusing theIntotrait.
§Return Value
- Returns a mutable reference to the current instance of the struct, enabling method chaining.
Sourcepub async fn send_body(
&mut self,
stream_lock: &ArcRwLockStream,
is_websocket: bool,
) -> ResponseResult
pub async fn send_body( &mut self, stream_lock: &ArcRwLockStream, is_websocket: bool, ) -> ResponseResult
Sourcepub async fn send(&mut self, stream_lock: &ArcRwLockStream) -> ResponseResult
pub async fn send(&mut self, stream_lock: &ArcRwLockStream) -> ResponseResult
Sourcepub async fn flush(&mut self, stream_lock: &ArcRwLockStream) -> ResponseResult
pub async fn flush(&mut self, stream_lock: &ArcRwLockStream) -> ResponseResult
Flush the TCP stream.
-
stream_lock: A reference to anArcRwLockStreamthat manages the TCP stream. -
Returns: A
ResponseResultindicating success or failure.
Sourcepub async fn close(&mut self, stream_lock: &ArcRwLockStream) -> ResponseResult
pub async fn close(&mut self, stream_lock: &ArcRwLockStream) -> ResponseResult
Closes the stream after sending the response.
This function is responsible for:
- Building the response using the
build()method. - Setting the response using the
set_response()method. - Shutting down the write half of the TCP stream to indicate no more data will be sent.
§Parameters
stream: A reference to theTcpStreamthat will be closed after sending the response.
§Returns
ResponseResult: The result of the operation, indicating whether the closure was successful or if an error occurred.
Sourcepub fn get_string(&self) -> String
pub fn get_string(&self) -> String
Converts the response to a formatted string representation.
- Returns: A
Stringcontaining 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 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 set_headers(&mut self, val: ResponseHeaders) -> &mut Self
pub fn get_body(&self) -> &ResponseBody
pub fn get_mut_body(&mut self) -> &mut ResponseBody
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more