reqwest-proxy-pool
Proxy pool middleware implementation for reqwest-middleware.
Features
✨ Comprehensive Proxy Support
- Automatic parsing of free SOCKS5/SOCKS5H proxies from multiple sources
- Per-host proxy pools with independent health-check policies
⚡ Intelligent Proxy Management
- Multiple proxy selection strategies (FastestResponse, MostReliable, TopKReliableRandom, RoundRobin, Random)
- Per-proxy minimum request interval to avoid bans
- Automatic retry mechanism for failed requests
- Retry strategy control (
DefaultSelection/NewProxyOnRetry) - Custom body classifier for business-level proxy health (anti-bot/captcha detection)
- Proxy cooldown with half-open probing after failures
- Reuse built clients via proxy-url cache to reduce rebuild overhead
🎯 Stability-First Goal
- Designed to absorb unstable proxy quality (timeouts, handshake errors, intermittent body-read failures) inside the library.
- Prefer request completion stability over single-attempt latency under noisy proxy pools.
🔧 Easy Configuration
- Simple builder pattern for configuration
- Seamless integration with reqwest middleware stack
Quickstart
Installation
Add to your Cargo.toml:
[]
= "0.13"
= "0.4"
= "0.5"
= { = "1", = ["full"] }
Usage
use ClientBuilder;
use ;
use Duration;
;
async
Notes
- For body-aware classification, middleware reads full response body into memory and rebuilds
reqwest::Responsebefore returning it. - This improves failure attribution and retry stability, but increases memory usage for large response bodies.
Configuration Options
ProxyPoolConfig:
| Option | Description | Default |
|---|---|---|
sources |
List of URLs providing proxy lists (shared by all host pools) | Required |
hosts |
List of HostConfig (one host = one pool) |
Required |
client_builder_factory |
Creates request client builder before proxy append | reqwest::Client::builder |
HostConfig:
| Option | Description | Default |
|---|---|---|
host |
Target host for this pool | Required |
primary |
Whether this host is fallback primary (exactly one must be true) |
false |
health_check_interval |
Interval for background health checks | 300s |
health_check_timeout |
Timeout for proxy health checks | 10s |
min_available_proxies |
Min available proxies | 3 |
health_check_url |
URL to test proxy health | "https://www.google.com" |
retry_count |
Number of retries for failed requests | 3 |
retry_strategy |
Retry behavior | DefaultSelection |
selection_strategy |
Proxy selection algorithm | FastestResponse |
reliable_top_k |
K used by TopKReliableRandom |
8 |
proxy_cooldown |
Cooldown duration after one proxy failure | 30s |
min_request_interval_ms |
Min interval per proxy request | 500 |
body_classifier |
Custom body classifier for proxy health | DefaultBodyClassifier |
Host-Based Routing (Multiple Pools)
use ;
let api_host = builder.build;
let web_host = builder.primary.build;
let config = builder
.sources
.hosts
.build;
let middleware = new.await?;
Routing Rules
- Request host matches a configured
HostConfig.host-> use that host pool. - Request host does not match -> use the unique
HostConfigwithprimary(true).
primary=true is required for exactly one host.
Migration (0.3 -> 0.4)
Breaking API changes in 0.4:
ResponseClassifier->BodyClassifierProxyResponseVerdict->ProxyBodyVerdict.response_classifier(...)->.body_classifier(...)HostConfig::danger_accept_invalid_certsremoved
New stability knobs:
ProxySelectionStrategy::TopKReliableRandomHostConfig::reliable_top_k(default8)HostConfig::proxy_cooldown(default30s)ProxyPoolConfig::client_builder_factory(...)for timeout/TLS/pool defaults on internally built proxied clients