pub struct Response { /* private fields */ }Expand description
Represents an HTTP response message.
Implementations§
Source§impl Response
impl Response
Sourcepub fn new(status: StatusCode) -> Self
pub fn new(status: StatusCode) -> Self
Create a new response with the provided status code and canonical reason.
Sourcepub fn builder(status: StatusCode) -> ResponseBuilder
pub fn builder(status: StatusCode) -> ResponseBuilder
Construct a builder for the response.
Sourcepub fn version(&self) -> HttpVersion
pub fn version(&self) -> HttpVersion
Return the HTTP version of the response.
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Return the status code.
Sourcepub fn reason_phrase(&self) -> &str
pub fn reason_phrase(&self) -> &str
Access the reason phrase used for the status line.
Sourcepub fn headers_mut(&mut self) -> &mut Headers
pub fn headers_mut(&mut self) -> &mut Headers
Borrow header map mutably.
Sourcepub fn body(&self) -> &ResponseBody
pub fn body(&self) -> &ResponseBody
Borrow the body representation.
Sourcepub fn set_status(&mut self, status: StatusCode)
pub fn set_status(&mut self, status: StatusCode)
Override the status code.
Sourcepub fn take_body(&mut self) -> ResponseBody
pub fn take_body(&mut self) -> ResponseBody
Remove and return the body, leaving an empty placeholder behind.
Sourcepub fn set_body(&mut self, body: ResponseBody)
pub fn set_body(&mut self, body: ResponseBody)
Replace the body with the provided representation.
Sourcepub fn set_body_bytes(&mut self, bytes: impl Into<Bytes>)
pub fn set_body_bytes(&mut self, bytes: impl Into<Bytes>)
Convenience helper for replacing the body with fully buffered bytes.
Sourcepub fn set_body_static(&mut self, bytes: &'static [u8])
pub fn set_body_static(&mut self, bytes: &'static [u8])
Replace the body with a static byte slice without copying.
Sourcepub fn set_body_text_static(&mut self, text: &'static str)
pub fn set_body_text_static(&mut self, text: &'static str)
Replace the body with a static UTF-8 string without copying.
Sourcepub fn strip_body_for_head(&mut self)
pub fn strip_body_for_head(&mut self)
Prepare the response for a HEAD reply by stripping the body while preserving the advertised payload length when known.
Sourcepub fn set_trailers(&mut self, trailers: Headers)
pub fn set_trailers(&mut self, trailers: Headers)
Replace the trailers with the provided header set.
Sourcepub fn take_trailers(&mut self) -> Option<Headers>
pub fn take_trailers(&mut self) -> Option<Headers>
Remove any trailers from the response and return them.
Sourcepub fn body_mut(&mut self) -> &mut ResponseBody
pub fn body_mut(&mut self) -> &mut ResponseBody
Borrow the body mutably.
Sourcepub fn set_version(&mut self, version: HttpVersion)
pub fn set_version(&mut self, version: HttpVersion)
Override the HTTP version.
Sourcepub fn set_reason(&mut self, reason: impl Into<String>)
pub fn set_reason(&mut self, reason: impl Into<String>)
Override the reason phrase.