pub struct Response { /* private fields */ }Expand description
A response to be serialized onto the connection.
Build one with Response::new or the status helpers, then chain
Response::header / Response::body. The engine fills in framing
headers (Content-Length, Connection, Date) at serialization time, so
handlers only set what they care about.
Implementations§
Source§impl Response
impl Response
Sourcepub fn new(status: StatusCode) -> Response
pub fn new(status: StatusCode) -> Response
A response with the given status, no headers, and an empty body.
Sourcepub fn text(body: impl Into<String>) -> Response
pub fn text(body: impl Into<String>) -> Response
200 OK with the given body and a Content-Type of text/plain.
Sourcepub fn status(status: StatusCode) -> Response
pub fn status(status: StatusCode) -> Response
A bodyless response carrying just a status, with a short text/plain
explanation as the body (useful for error pages).
Sourcepub fn redirect(status: StatusCode, location: impl Into<String>) -> Response
pub fn redirect(status: StatusCode, location: impl Into<String>) -> Response
A redirect to location with the given 3xx status.
Sourcepub fn header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Response
pub fn header( self, name: impl Into<String>, value: impl Into<String>, ) -> Response
Add a header field (builder style), keeping any existing same-named field.
Sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
The status code.
Sourcepub fn headers_mut(&mut self) -> &mut Headers
pub fn headers_mut(&mut self) -> &mut Headers
Mutable access to the response headers.
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 UnsafeUnpin 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