[][src]Struct rocket::http::hyper::Response

pub struct Response<'a, W = Fresh> where
    W: Any
{ pub version: HttpVersion, // some fields omitted }

The outgoing half for a Tcp connection, created by a Server and given to a Handler.

The default StatusCode for a Response is 200 OK.

There is a Drop implementation for Response that will automatically write the head and flush the body, if the handler has not already done so, so that the server doesn't accidentally leave dangling requests.

Fields

version: HttpVersion

The HTTP version of this response.

Methods

impl<'a, W> Response<'a, W> where
    W: Any
[src]

pub fn status(&self) -> StatusCode[src]

The status of this response.

pub fn headers(&self) -> &Headers[src]

The headers of this response.

Important traits for Response<'a, Streaming>
pub fn construct(
    version: HttpVersion,
    body: HttpWriter<&'a mut (dyn Write + 'a)>,
    status: StatusCode,
    headers: &'a mut Headers
) -> Response<'a, Fresh>
[src]

Construct a Response from its constituent parts.

pub fn deconstruct(
    self
) -> (HttpVersion, HttpWriter<&'a mut (dyn Write + 'a)>, StatusCode, &'a mut Headers)
[src]

Deconstruct this Response into its constituent parts.

impl<'a> Response<'a, Fresh>[src]

Important traits for Response<'a, Streaming>
pub fn new(
    stream: &'a mut (dyn Write + 'a),
    headers: &'a mut Headers
) -> Response<'a, Fresh>
[src]

Creates a new Response that can be used to write to a network stream.

pub fn send(self, body: &[u8]) -> Result<(), Error>[src]

Writes the body and ends the response.

This is a shortcut method for when you have a response with a fixed size, and would only need a single write call normally.

Example

fn handler(res: Response) {
    res.send(b"Hello World!").unwrap();
}

The above is the same, but shorter, than the longer:

use std::io::Write;
use hyper::header::ContentLength;
fn handler(mut res: Response) {
    let body = b"Hello World!";
    res.headers_mut().set(ContentLength(body.len() as u64));
    let mut res = res.start().unwrap();
    res.write_all(body).unwrap();
}

pub fn start(self) -> Result<Response<'a, Streaming>, Error>[src]

Consume this Response, writing the Headers and Status and creating a Response

pub fn status_mut(&mut self) -> &mut StatusCode[src]

Get a mutable reference to the status.

pub fn headers_mut(&mut self) -> &mut Headers[src]

Get a mutable reference to the Headers.

impl<'a> Response<'a, Streaming>[src]

pub fn end(self) -> Result<(), Error>[src]

Flushes all writing of a response to the client.

Trait Implementations

impl<'a, W> Debug for Response<'a, W> where
    W: Any + Debug
[src]

impl<'a, T> Drop for Response<'a, T> where
    T: Any
[src]

impl<'a> Write for Response<'a, Streaming>[src]

Auto Trait Implementations

impl<'a, W = Fresh> !RefUnwindSafe for Response<'a, W>

impl<'a, W = Fresh> !Send for Response<'a, W>

impl<'a, W = Fresh> !Sync for Response<'a, W>

impl<'a, W> Unpin for Response<'a, W> where
    W: Unpin

impl<'a, W = Fresh> !UnwindSafe for Response<'a, W>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, I> AsResult<T, I> for T where
    I: Input, 

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoCollection<T> for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Typeable for T where
    T: Any

impl<W> WriteBytesExt for W where
    W: Write + ?Sized