pub struct Response { /* private fields */ }Expand description
Represents an HTTP response.
§Fields
version: The HTTP version of the response (e.g., HTTP/1.1).status_code: The status code of the response (e.g., 200, 404).reason_phrase: The reason phrase corresponding to the status code (e.g., OK, Not Found).headers: A collection of HTTP headers as key-value pairs.body: The binary body of the response.response: The serialized HTTP response including headers and body.
Implementations§
Source§impl Response
impl Response
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 Cow<'a, str>, allowing for efficient handling of both owned and borrowed string data.
§Parameters
key: The header key, which will be converted into aCow<'a, str>.value: The value of the header, which will be converted into aCow<'a, str>.
§Returns
- Returns a mutable reference to the current instance (
&mut Self), allowing for method chaining.
Sourcepub fn build(&mut self) -> ResponseData
pub fn build(&mut self) -> ResponseData
Builds the full HTTP response as a byte vector.
§Returns
- The serialized HTTP response including headers and body.
Source§impl Response
impl Response
pub fn get_version(&self) -> &Cow<'static, str>
pub fn set_version(&mut self, val: Cow<'static, str>) -> &mut Self
pub fn get_status_code(&self) -> &usize
pub fn set_status_code(&mut self, val: usize) -> &mut Self
pub fn get_reason_phrase(&self) -> &Cow<'static, str>
pub fn set_reason_phrase(&mut self, val: Cow<'static, str>) -> &mut Self
pub fn get_headers(&self) -> &HashMap<Cow<'static, str>, Cow<'static, str>>
pub fn set_headers( &mut self, val: HashMap<Cow<'static, str>, Cow<'static, str>>, ) -> &mut Self
pub fn get_body(&self) -> &ResponseBody
pub fn set_body(&mut self, val: ResponseBody) -> &mut Self
pub fn get_response(&self) -> &ResponseData
pub fn set_response(&mut self, val: ResponseData) -> &mut Self
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
Mutably borrows from an owned value. Read more