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
impl RotatingClient
Sourcepub fn builder() -> RotatingClientBuilder
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();Sourcepub async fn get(&self, url: impl IntoUrl) -> Result<Response, Error>
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());Sourcepub fn request(&self, method: Method, url: impl IntoUrl) -> RequestBuilder
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.
Sourcepub async fn send(
&self,
request_builder: RequestBuilder,
) -> Result<Response, Error>
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.
Sourcepub async fn execute(&self, request: Request) -> Result<Response, Error>
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.
Sourcepub fn proxies(&self) -> &ProxyList
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
impl Clone for RotatingClient
Source§fn clone(&self) -> RotatingClient
fn clone(&self) -> RotatingClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more