Skip to main content

RotatingClient

Struct RotatingClient 

Source
pub struct RotatingClient { /* private fields */ }
Expand description

An HTTP client that rotates across a pool of proxies, rate-limits requests per host, and retries transient failures with backoff.

Build one with RotatingClient::builder. Proxies are optional: with none configured, RotatingClient behaves as a plain rate-limited, retrying client that ignores proxy environment variables. See the crate-level docs for what is retried and for a full example.

Cloning is cheap (an Arc bump) and clones share everything: connection pools, proxy cooldown state, and the rate limiter.

Implementations§

Source§

impl RotatingClient

Source

pub fn builder() -> RotatingClientBuilder

Starts building a RotatingClient.

§Examples
use reqwest_rotate::RotatingClient;
use std::time::Duration;

let client = RotatingClient::builder()
    .rate_limit(Duration::from_millis(200))
    .retries(2)
    .build()
    .unwrap();
Source

pub async fn get(&self, url: impl IntoUrl) -> Result<Response, Error>

Sends a GET request to url, applying rate limiting, proxy rotation, and retries.

§Errors

Returns Error::Reqwest when the request cannot be built or when the last attempt fails after the retries are used up; see Error for the full set.

§Examples
use reqwest_rotate::RotatingClient;

let client = RotatingClient::builder().build()?;
let response = client.get("https://example.com").await?;
println!("status: {}", response.status());
Source

pub fn request(&self, method: Method, url: impl IntoUrl) -> RequestBuilder

Starts building a request with an arbitrary method, using this client’s configuration (headers such as User-Agent). The returned RequestBuilder wraps reqwest::RequestBuilder: call send on it to route the request through rate limiting, proxy rotation, and retries, the same as get does. Call build instead if you only want the Request, or into_inner to get the plain reqwest::RequestBuilder back — its own .send() bypasses rotation, rate limiting and retries, sending directly with no proxy.

Source

pub async fn send( &self, request_builder: RequestBuilder, ) -> Result<Response, Error>

Builds request_builder and sends it, applying rate limiting, proxy rotation, and retries. Takes a plain reqwest::RequestBuilder, e.g. one built directly against your own reqwest::Client, or a RequestBuilder unwrapped with into_inner. For the common case, call send on the request result directly instead.

§Errors

Returns Error::Reqwest when the request cannot be built or when the last attempt fails after the retries are used up; see Error for the full set.

Source

pub async fn execute(&self, request: Request) -> Result<Response, Error>

Sends a pre-built reqwest::Request, applying rate limiting, proxy rotation, and retries.

§Errors

Returns Error::Reqwest when the last attempt fails after the retries are used up; see Error for the full set.

Source

pub fn proxies(&self) -> &ProxyList

Returns the ProxyList this client rotates over: e.g. to inspect or react to which proxies are currently in cooldown.

Calling pick() on the returned list advances this client’s rotation and clears an expired cooldown; as_slice(), len() and in_cooldown() are the read-only accessors.

Trait Implementations§

Source§

impl Clone for RotatingClient

Source§

fn clone(&self) -> RotatingClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RotatingClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more