pub struct Response { /* private fields */ }
Expand description
Worker response for HTTP requests.
The Response is created/accessed from ctx.response()
and has a builder-like api.
Implementations§
Source§impl Response
impl Response
Sourcepub fn body<T: Into<Body>>(&mut self, body: T) -> &mut Self
pub fn body<T: Into<Body>>(&mut self, body: T) -> &mut Self
Sets response body to the binary data
Sourcepub fn json<T: Serialize>(&mut self, value: &T) -> Result<&mut Self, Error>
pub fn json<T: Serialize>(&mut self, value: &T) -> Result<&mut Self, Error>
Sets response body to value serialized as json, and sets content-type to application/json
Sourcepub fn text<T: Into<String>>(&mut self, text: T) -> &mut Self
pub fn text<T: Into<String>>(&mut self, text: T) -> &mut Self
Sets response body to the text string, encoded as utf-8
Sourcepub fn header<K: AsRef<str>, V: AsRef<str>>(
&mut self,
key: K,
val: V,
) -> Result<&mut Self, Error>
pub fn header<K: AsRef<str>, V: AsRef<str>>( &mut self, key: K, val: V, ) -> Result<&mut Self, Error>
Sets a header for this response
Sourcepub fn content_type<T: AsRef<str>>(
&mut self,
ctype: T,
) -> Result<&mut Self, Error>
pub fn content_type<T: AsRef<str>>( &mut self, ctype: T, ) -> Result<&mut Self, Error>
Sets response content type
Sourcepub fn get_status(&self) -> u16
pub fn get_status(&self) -> u16
Returns the status of this response
Sourcepub fn get_headers(&self) -> Option<&Headers>
pub fn get_headers(&self) -> Option<&Headers>
Returns headers for this response, or None if no headers have been set
Sourcepub fn is_unset(&self) -> bool
pub fn is_unset(&self) -> bool
True if the response has not been filled in (none of status(), text() or body() has been called). (even if status() is called with 200 status or body is set to empty) This could be used as a flag for chained handlers to determine whether a previous handler has filled in the response yet. Setting headers (including content_type or user_agent) does not mark the request “set” This is so that headers can be set at the top of a handler, before errors may occur