pub struct NoOpClient { /* private fields */ }Expand description
A no-op HTTP client that always fails with an error.
This client is useful for testing VCR in replay mode to ensure that no real HTTP requests are made. Any attempt to send a request will result in an error.
§Usage
use http_client_vcr::{VcrClient, VcrMode, NoOpClient};
use http_client::HttpClient;
use http_types::{Request, Method, Url};
// Ensure no real HTTP requests can be made
let vcr_client = VcrClient::builder("fixtures/test.yaml")
.inner_client(Box::new(NoOpClient::new()))
.mode(VcrMode::Replay) // Only replay from cassette
.build()
.await?;
// This will work if the request is in the cassette
let request = Request::new(Method::Get, Url::parse("https://example.com")?);
let response = vcr_client.send(request).await?;
// If not in cassette, VCR will return an error before reaching NoOpClient
// If somehow a request reaches NoOpClient, it will panic with a clear messageImplementations§
Source§impl NoOpClient
impl NoOpClient
Sourcepub fn with_message(message: impl Into<String>) -> Self
pub fn with_message(message: impl Into<String>) -> Self
Create a NoOpClient with a custom error message.
Sourcepub fn panicking() -> PanickingNoOpClient
pub fn panicking() -> PanickingNoOpClient
Create a NoOpClient that panics instead of returning an error. This is useful for catching unexpected HTTP requests during development.
Trait Implementations§
Source§impl Clone for NoOpClient
impl Clone for NoOpClient
Source§fn clone(&self) -> NoOpClient
fn clone(&self) -> NoOpClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for NoOpClient
impl Debug for NoOpClient
Source§impl Default for NoOpClient
impl Default for NoOpClient
Source§impl HttpClient for NoOpClient
impl HttpClient for NoOpClient
Source§fn send<'life0, 'async_trait>(
&'life0 self,
req: Request,
) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn send<'life0, 'async_trait>(
&'life0 self,
req: Request,
) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Perform a request.
Auto Trait Implementations§
impl Freeze for NoOpClient
impl RefUnwindSafe for NoOpClient
impl Send for NoOpClient
impl Sync for NoOpClient
impl Unpin for NoOpClient
impl UnwindSafe for NoOpClient
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