pub struct Response { /* private fields */ }Expand description
Creates HTTP response.
§Example
let res = Response::new();
res.status(status::OK);
res.header("key", "value");
res.header("another", "value");
res.body_str("Hello world");
// write response to the socket
res.write(writer)
Implementations§
Source§impl Response
impl Response
Sourcepub fn status(&mut self, status: &'static str)
pub fn status(&mut self, status: &'static str)
Attache status to the http response (can use status module).
res.status(status::OK);Sourcepub fn header(&mut self, name: &'static str, value: &'static str)
pub fn header(&mut self, name: &'static str, value: &'static str)
Attache single header to http response, can be reused.
res.header("Header", "Value");Sourcepub fn body_vec(&mut self, body: Vec<u8>)
pub fn body_vec(&mut self, body: Vec<u8>)
Attache Vec body to the http response.
let body = vec![....];
res.body_vec(body);Sourcepub fn body_str(&mut self, body: &str)
pub fn body_str(&mut self, body: &str)
Transform &str to Vec and attach it to the http response.
res.body_str("Hello world");Sourcepub fn write<S: AsyncWrite>(&self, writer: S) -> WriteAll<S>
pub fn write<S: AsyncWrite>(&self, writer: S) -> WriteAll<S>
Process Response and return future which writes response to the AsyncWrite socket.
let (read, write) = socket.split();
...
res.write(write);Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnsafeUnpin for Response
impl UnwindSafe for Response
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more