[−][src]Struct vial::Response
Each request ultimately ends in a Response
that is served to the
client and then discarded, like fallen flower petals. Together
with Request
and
Responder
it forms the holy trinity of
R
's in Vial.
Rather than use the "Builder" pattern like more mature and better
designed libraries, Vial's Response
lets you set properties
either directly or using Builder-style methods:
vial::routes! { GET "/404" => |_| Response::from(404) .with_header("Content-Type", "text/plain") .with_body("404 Not Found"); }
It also defaults to text/html
, so you need to use
with_header()
or
header()
to send plain text.
Implementations
impl Response
[src]
pub fn new() -> Response
[src]
Create a new, empty, 200 response - ready for HTML!
pub fn code(&self) -> usize
[src]
HTTP Status Code
pub fn content_type(&self) -> &str
[src]
Either the inferred or user-set Content-Type for this Response.
pub fn body(&self) -> &str
[src]
Response body.
pub fn headers(&self) -> &HashMap<String, String>
[src]
Take a peek at all the headers for this response.
pub fn header(&self, name: &str) -> Option<&str>
[src]
Get an individual header. name
is case insensitive.
pub fn set_header(&mut self, name: &str, value: &str)
[src]
Set an individual header.
pub fn from<T: Into<Response>>(from: T) -> Response
[src]
Convert into a Response.
pub fn from_asset(path: &str) -> Response
[src]
Create a response from an asset. See the
asset
module for more information on
using assets.
pub fn from_reader(reader: Box<dyn Read>) -> Response
[src]
Create a response from a (boxed) io::Read.
pub fn from_file(path: &str) -> Response
[src]
Creates a response from a file on disk. TODO: Path?
pub fn from_error<E: Error>(err: E) -> Response
[src]
Creates a 500 response from an error, displaying it.
pub fn from_header(name: &str, value: &str) -> Response
[src]
Creates a new Response and sets the given header, in addition to the defaults.
pub fn from_body<S: AsRef<str>>(body: S) -> Response
[src]
Creates a new default Response with the given body.
pub fn from_text<S: AsRef<str>>(text: S) -> Response
[src]
Creates a new text/plain
Response with the given body.
pub fn from_code(code: usize) -> Response
[src]
Creates a new response with the given HTTP Status Code.
pub fn with_code(self, code: usize) -> Response
[src]
Creates a new response with the given HTTP Status Code.
pub fn with_body<S: AsRef<str>>(self, body: S) -> Response
[src]
Body builder. Returns a Response with the given body.
pub fn with_text<S: AsRef<str>>(self, text: S) -> Response
[src]
Returns a text/plain
Response with the given body.
pub fn with_reader(self, reader: Box<dyn Read>) -> Response
[src]
Returns a Response using the given reader for the body.
pub fn with_asset(self, path: &str) -> Response
[src]
Uses an asset for the given body and sets the Content-Type
header based on the file's extension.
See the asset
module for more
information on using assets.
pub fn with_file(self, path: &str) -> Response
[src]
Sets this Response's body to the body of the given file and
sets the Content-Type
header based on the file's extension.
pub fn with_error<E: Error>(self, err: E) -> Response
[src]
Sets the response code to 500 and the body to the error's text.
pub fn with_header(self, key: &str, value: &str) -> Response
[src]
Returns a Response with the given header set to the value.
pub fn len(&self) -> usize
[src]
Length of the body.
pub fn is_empty(&self) -> bool
[src]
Is ths response empty?
pub fn redirect_to<U: AsRef<str>>(url: U) -> Response
[src]
Returns a 302 redirect to the given URL.
pub fn write<W: Write>(self, w: W) -> Result<()>
[src]
Writes this response to a stream.
Trait Implementations
impl Debug for Response
[src]
impl Default for Response
[src]
impl Display for Response
[src]
impl<'_> From<&'_ String> for Response
[src]
impl<'_> From<&'_ str> for Response
[src]
impl<'_> From<Cow<'_, [u8]>> for Response
[src]
impl From<String> for Response
[src]
impl From<usize> for Response
[src]
impl PartialEq<Response> for Response
[src]
impl Responder for Response
[src]
fn to_response(self) -> Response
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Response
impl !Send for Response
impl !Sync for Response
impl Unpin for Response
impl !UnwindSafe for Response
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,