pub struct RecordingHttpClient { /* private fields */ }Available on crate feature
test-utils only.Expand description
An HttpClientExt implementation that records unary requests and returns
a fixed response.
Implementations§
Source§impl RecordingHttpClient
impl RecordingHttpClient
Sourcepub fn new(response_body: impl Into<Bytes>) -> Self
pub fn new(response_body: impl Into<Bytes>) -> Self
Create a client that returns response_body for unary requests.
Sourcepub fn with_error(status: StatusCode, message: impl Into<String>) -> Self
pub fn with_error(status: StatusCode, message: impl Into<String>) -> Self
Create a client that returns an HTTP status error for unary requests.
Sourcepub fn with_error_response(status: StatusCode, body: impl Into<Bytes>) -> Self
pub fn with_error_response(status: StatusCode, body: impl Into<Bytes>) -> Self
Create a client that returns a non-success HTTP response (status and body) for unary requests, instead of a transport-level error.
Sourcepub fn with_error_headers(
status: StatusCode,
message: impl Into<String>,
headers: HeaderMap,
) -> Self
pub fn with_error_headers( status: StatusCode, message: impl Into<String>, headers: HeaderMap, ) -> Self
Create a client whose transport reports a non-success status and preserves the failed response’s headers, as the bundled reqwest client does (rig#2210).
Sourcepub fn with_error_response_headers(
status: StatusCode,
body: impl Into<Bytes>,
headers: HeaderMap,
) -> Self
pub fn with_error_response_headers( status: StatusCode, body: impl Into<Bytes>, headers: HeaderMap, ) -> Self
Create a client that hands back a non-success HTTP response carrying
headers, instead of a transport-level error.
Sourcepub fn requests(&self) -> Vec<CapturedHttpRequest>
pub fn requests(&self) -> Vec<CapturedHttpRequest>
Return the requests captured so far.
Sourcepub fn set_response(&self, response: MockHttpResponse)
pub fn set_response(&self, response: MockHttpResponse)
Replace the scripted unary response.
Trait Implementations§
Source§impl Clone for RecordingHttpClient
impl Clone for RecordingHttpClient
Source§impl Debug for RecordingHttpClient
impl Debug for RecordingHttpClient
Source§impl Default for RecordingHttpClient
impl Default for RecordingHttpClient
Source§impl HttpClientExt for RecordingHttpClient
impl HttpClientExt for RecordingHttpClient
Source§fn send<T, U>(
&self,
req: Request<T>,
) -> impl Future<Output = Result<Response<LazyBody<U>>>> + WasmCompatSend + 'static
fn send<T, U>( &self, req: Request<T>, ) -> impl Future<Output = Result<Response<LazyBody<U>>>> + WasmCompatSend + 'static
Sends a request and returns headers with a lazy body converted from bytes to
U.Source§fn send_multipart<U>(
&self,
req: Request<MultipartForm>,
) -> impl Future<Output = Result<Response<LazyBody<U>>>> + WasmCompatSend + 'static
fn send_multipart<U>( &self, req: Request<MultipartForm>, ) -> impl Future<Output = Result<Response<LazyBody<U>>>> + WasmCompatSend + 'static
Sends a multipart request and returns headers with a lazy body converted to
U.Source§fn send_streaming<T>(
&self,
_req: Request<T>,
) -> impl Future<Output = Result<StreamingResponse>> + WasmCompatSend
fn send_streaming<T>( &self, _req: Request<T>, ) -> impl Future<Output = Result<StreamingResponse>> + WasmCompatSend
Sends a request and returns headers with a stream of transport byte chunks.
Auto Trait Implementations§
impl Freeze for RecordingHttpClient
impl RefUnwindSafe for RecordingHttpClient
impl Send for RecordingHttpClient
impl Sync for RecordingHttpClient
impl Unpin for RecordingHttpClient
impl UnsafeUnpin for RecordingHttpClient
impl UnwindSafe for RecordingHttpClient
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