Struct rocket::http::hyper::Response [−][src]
pub struct Response<'a, W = Fresh> where
W: Any, {
pub version: HttpVersion,
// some fields omitted
}
Expand description
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.
Implementations
The status of this response.
pub fn construct(
version: HttpVersion,
body: HttpWriter<&'a mut (dyn Write + 'a)>,
status: StatusCode,
headers: &'a mut Headers
) -> Response<'a, Fresh>ⓘ
pub fn construct(
version: HttpVersion,
body: HttpWriter<&'a mut (dyn Write + 'a)>,
status: StatusCode,
headers: &'a mut Headers
) -> Response<'a, Fresh>ⓘ
Construct a Response from its constituent parts.
pub fn deconstruct(
self
) -> (HttpVersion, HttpWriter<&'a mut (dyn Write + 'a)>, StatusCode, &'a mut Headers)
pub fn deconstruct(
self
) -> (HttpVersion, HttpWriter<&'a mut (dyn Write + 'a)>, StatusCode, &'a mut Headers)
Deconstruct this Response into its constituent parts.
Creates a new Response that can be used to write to a network stream.
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();
}
Consume this Response
Get a mutable reference to the status.
Get a mutable reference to the Headers.
Trait Implementations
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
Attempts to write an entire buffer into this writer. Read more
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Auto Trait Implementations
impl<'a, W = Fresh> !RefUnwindSafe for Response<'a, W>
impl<'a, W = Fresh> !UnwindSafe for Response<'a, W>
Blanket Implementations
Mutably borrows from an owned value. Read more
Writes an unsigned 8 bit integer to the underlying writer. Read more
Writes a signed 8 bit integer to the underlying writer. Read more
Writes an unsigned 16 bit integer to the underlying writer. Read more
Writes a signed 16 bit integer to the underlying writer. Read more
Writes an unsigned 24 bit integer to the underlying writer. Read more
Writes a signed 24 bit integer to the underlying writer. Read more
Writes an unsigned 32 bit integer to the underlying writer. Read more
Writes a signed 32 bit integer to the underlying writer. Read more
Writes an unsigned 48 bit integer to the underlying writer. Read more
Writes a signed 48 bit integer to the underlying writer. Read more
Writes an unsigned 64 bit integer to the underlying writer. Read more
Writes a signed 64 bit integer to the underlying writer. Read more
Writes an unsigned 128 bit integer to the underlying writer.
Writes a signed 128 bit integer to the underlying writer.
Writes an unsigned n-bytes integer to the underlying writer. Read more
Writes a signed n-bytes integer to the underlying writer. Read more
Writes an unsigned n-bytes integer to the underlying writer. Read more
Writes a signed n-bytes integer to the underlying writer. Read more
Writes a IEEE754 single-precision (4 bytes) floating point number to the underlying writer. Read more