Struct gotham::test::TestResponse
[−]
[src]
pub struct TestResponse { /* fields omitted */ }
Wrapping struct for the Response
returned by a TestClient
. Provides access to the
Response
value via the Deref
and DerefMut
traits, and also provides a function for
awaiting a completed response body.
Examples
use gotham::test::TestServer; let test_server = TestServer::new(|| Ok(my_handler)).unwrap(); let response = test_server.client().get("http://localhost/").perform().unwrap(); assert_eq!(response.status(), StatusCode::Ok); let body = response.read_body().unwrap(); assert_eq!(&body[..], b"This is the body content.");
Methods
impl TestResponse
[src]
fn read_body(self) -> Result<Vec<u8>>
[src]
Awaits the body of the underlying Response
, and returns it. This will cause the event
loop to execute until the Response
body has been fully read into the Vec<u8>
.
fn read_utf8_body(self) -> Result<String>
[src]
Awaits the UTF-8 encoded body of the underlying Response
, and returns the String
. This
will cause the event loop to execute until the Response
body has been fully read and the
String
created.
Methods from Deref<Target = Response>
fn version(&self) -> HttpVersion
[src]
Get the HTTP version of this response.
fn headers(&self) -> &Headers
[src]
Get the headers from the response.
fn headers_mut(&mut self) -> &mut Headers
[src]
Get a mutable reference to the headers.
fn status(&self) -> StatusCode
[src]
Get the status from the server.
fn set_status(&mut self, status: StatusCode)
[src]
Set the StatusCode
for this response.
fn with_status(self, status: StatusCode) -> Response<B>
[src]
Set the status and move the Response.
Useful for the "builder-style" pattern.
fn with_header<H>(self, header: H) -> Response<B> where
H: Header,
[src]
H: Header,
Set a header and move the Response.
Useful for the "builder-style" pattern.
fn with_headers(self, headers: Headers) -> Response<B>
[src]
Set the headers and move the Response.
Useful for the "builder-style" pattern.
fn set_body<T>(&mut self, body: T) where
T: Into<B>,
[src]
T: Into<B>,
Set the body.
fn with_body<T>(self, body: T) -> Response<B> where
T: Into<B>,
[src]
T: Into<B>,
Set the body and move the Response.
Useful for the "builder-style" pattern.
fn body_ref(&self) -> Option<&B>
[src]
Read the body.
Trait Implementations
impl Deref for TestResponse
[src]
type Target = Response
The resulting type after dereferencing.
fn deref(&self) -> &Response
[src]
Dereferences the value.