pub struct ProxyRotator { /* private fields */ }Expand description
A pool of validated proxies plus a selection strategy.
Construct via ProxyRotator::build. Returns Ok(None) when there are no
proxies (caller then connects directly, preserving today’s behaviour).
Implementations§
Source§impl ProxyRotator
impl ProxyRotator
Sourcepub fn build(
list: &[String],
single: Option<&str>,
strategy: ProxyRotation,
) -> Result<Option<Self>, String>
pub fn build( list: &[String], single: Option<&str>, strategy: ProxyRotation, ) -> Result<Option<Self>, String>
Build a rotator with precedence: a non-empty list wins; otherwise the
single single proxy becomes a pool of one; otherwise Ok(None).
Every entry is validated — any malformed URL is a hard error (no silent
no-proxy fallback). The error is a human-readable string the caller maps
to a crate::CrwError.
Sourcepub fn pick(&self, host_key: Option<&str>) -> &ProxyEntry
pub fn pick(&self, host_key: Option<&str>) -> &ProxyEntry
Select a proxy for a request. host_key is used only by
ProxyRotation::StickyPerHost; pass the normalized target host.
Sourcepub fn pick_index(&self, host_key: Option<&str>) -> usize
pub fn pick_index(&self, host_key: Option<&str>) -> usize
Index into the validated pool for this request, applying the strategy.
StickyPerHost is stateless: the index is a deterministic hash of the
host modulo the pool size. This keeps a host pinned to one proxy for the
rotator’s lifetime with no per-host map (no unbounded growth, no lock, and
— crucially — no cursor side-effect, so repeated picks for the same host
are idempotent and HTTP + CDP always agree).