pub struct Response {
pub status: Status,
pub headers: Headers,
pub body: Vec<u8>,
/* private fields */
}Expand description
An outgoing response.
Fields§
§status: Status§headers: Headers§body: Vec<u8>Implementations§
Source§impl Response
impl Response
pub fn new(status: Status) -> Self
Sourcepub fn upgrading(self, upgrade: impl Upgrade) -> Self
pub fn upgrading(self, upgrade: impl Upgrade) -> Self
Answer 101 and hand the connection to another protocol.
The caller sets whatever headers the new protocol’s handshake requires; this only arranges for the socket to be handed over afterwards.
Sourcepub fn streaming(self, body: impl Upgrade) -> Self
pub fn streaming(self, body: impl Upgrade) -> Self
Keep the status and headers, and hand the connection over once they are written — for a body that is produced over time rather than known now.
This is what an event stream is: a 200 whose body is events written
as they happen, for as long as the client stays. upgrading is the
same mechanism with a 101, for a protocol that stops being HTTP.
Sourcepub fn take_upgrade(&mut self) -> Option<Upgrader>
pub fn take_upgrade(&mut self) -> Option<Upgrader>
Take the upgrade out of a dispatched response.
Public so a test can drive an upgrade through the router rather than only over a real socket.
pub fn ok() -> Self
pub fn no_content() -> Self
pub fn not_found() -> Self
Sourcepub fn redirect(location: impl Into<String>) -> Self
pub fn redirect(location: impl Into<String>) -> Self
A 302 redirect. Use Response::see_other after a form submission so
the browser switches to GET.
pub fn see_other(location: impl Into<String>) -> Self
pub fn json(value: impl Into<Json>) -> Self
pub fn html(body: impl Into<String>) -> Self
pub fn text(body: impl Into<String>) -> Self
pub fn with_status(self, status: impl Into<Status>) -> Self
pub fn with_header(self, name: &str, value: impl Into<String>) -> Self
pub fn with_body(self, body: impl Into<Vec<u8>>) -> Self
pub fn with_json(self, value: impl Into<Json>) -> Self
pub fn with_html(self, body: impl Into<String>) -> Self
pub fn with_text(self, body: impl Into<String>) -> Self
Expire a cookie on the client.