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 with_status(self, status: StatusCode) -> Response
pub fn with_status(self, status: StatusCode) -> Response
Override the status code (builder style), keeping headers and body.
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§
Source§impl IntoResponse for Response
impl IntoResponse for Response
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
self and produce the response to send.