pub struct Response { /* private fields */ }Expand description
A response to be returned to the client.
You do not always need to use this struct directly as endpoints can
return anything implementing Responder. However this is the most flexible
way to construct a reply, and it implements Responder (the “identity” implementation).
Implementations§
Source§impl Response
impl Response
Sourcepub fn status(s: StatusCode) -> Self
pub fn status(s: StatusCode) -> Self
Create an empty response with the given status code
Sourcepub fn set_status(&mut self, s: StatusCode)
pub fn set_status(&mut self, s: StatusCode)
Set the status code of a response
Sourcepub fn get_status(&self) -> StatusCode
pub fn get_status(&self) -> StatusCode
Get the status code of a response
Sourcepub fn reader(self, r: impl AsyncRead + Send + 'static) -> Self
pub fn reader(self, r: impl AsyncRead + Send + 'static) -> Self
Set the body to an AsyncRead object
Sourcepub async fn path(self, path: impl AsRef<Path>) -> Result<Self>
pub async fn path(self, path: impl AsRef<Path>) -> Result<Self>
Set the body to the content of a file given by a Path Also sets a content type by guessing the mime type from the path name
Sourcepub fn json(self, body: impl Serialize) -> Result<Self>
pub fn json(self, body: impl Serialize) -> Result<Self>
Set the body of the response to a JSON payload
Sourcepub fn form(self, body: impl Serialize) -> Result<Self>
pub fn form(self, body: impl Serialize) -> Result<Self>
Set the body of the response to form data
Sourcepub fn set_header<H: Header>(&mut self, h: H)
pub fn set_header<H: Header>(&mut self, h: H)
Set a header (without consuming self - useful outside of method chains)
Sourcepub fn raw_header<N, K>(self, name: N, key: K) -> Result<Self>where
N: TryInto<HeaderName>,
K: TryInto<HeaderValue>,
<N as TryInto<HeaderName>>::Error: Into<Error>,
<K as TryInto<HeaderValue>>::Error: Into<Error>,
pub fn raw_header<N, K>(self, name: N, key: K) -> Result<Self>where
N: TryInto<HeaderName>,
K: TryInto<HeaderValue>,
<N as TryInto<HeaderName>>::Error: Into<Error>,
<K as TryInto<HeaderValue>>::Error: Into<Error>,
Set a raw header (from the http crate)
Sourcepub fn set_raw_header<N, K>(&mut self, name: N, key: K) -> Result<()>where
N: TryInto<HeaderName>,
K: TryInto<HeaderValue>,
<N as TryInto<HeaderName>>::Error: Into<Error>,
<K as TryInto<HeaderValue>>::Error: Into<Error>,
pub fn set_raw_header<N, K>(&mut self, name: N, key: K) -> Result<()>where
N: TryInto<HeaderName>,
K: TryInto<HeaderValue>,
<N as TryInto<HeaderName>>::Error: Into<Error>,
<K as TryInto<HeaderValue>>::Error: Into<Error>,
Set a raw header (without consuming self)
Sourcepub fn into_inner(self) -> Response<Body>
pub fn into_inner(self) -> Response<Body>
Consume this response and return the inner hyper::Response