pub struct TestResponse { /* private fields */ }Expand description
The response returned by TestRequestBuilder::send.
Wraps an http::Response<BoxBody> and provides convenience methods for
inspecting the status, headers, and body in tests.
Implementations§
Source§impl TestResponse
impl TestResponse
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Return the response status code.
Sourcepub async fn bytes(self) -> Result<Bytes, BodyError>
pub async fn bytes(self) -> Result<Bytes, BodyError>
Consume the response and collect the full body as Bytes.
§Errors
Returns BodyError::Stream if the body stream produces an error.
Sourcepub async fn text(self) -> Result<String, BodyError>
pub async fn text(self) -> Result<String, BodyError>
Consume the response and decode the body as a UTF-8 string.
§Errors
Returns BodyError::Stream if the body stream produces an error,
or BodyError::Utf8 if the bytes are not valid UTF-8.
Sourcepub async fn json<T: DeserializeOwned>(self) -> Result<T, BodyError>
pub async fn json<T: DeserializeOwned>(self) -> Result<T, BodyError>
Consume the response and deserialize the body as JSON.
§Errors
Returns BodyError::Stream if the body stream produces an error,
BodyError::Json if deserialization fails.
Auto Trait Implementations§
impl !RefUnwindSafe for TestResponse
impl !UnwindSafe for TestResponse
impl Freeze for TestResponse
impl Send for TestResponse
impl Sync for TestResponse
impl Unpin for TestResponse
impl UnsafeUnpin for TestResponse
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