Skip to main content

reqwest_proxy_pool/
classifier.rs

1//! Response classification for proxy health feedback.
2
3/// Result of classifying a response from a proxy.
4#[derive(Debug, Clone, Copy, PartialEq)]
5pub enum ProxyResponseVerdict {
6    /// Response is good. Proxy records a success.
7    Success,
8    /// Proxy is blocked (e.g. captcha, anti-bot). Records failure, retries with another proxy.
9    ProxyBlocked,
10    /// Server-side issue unrelated to proxy. Returns response as-is without affecting proxy stats.
11    Passthrough,
12}
13
14/// Classify responses to determine proxy health at the business level.
15///
16/// Implement this trait to detect anti-bot responses (captchas, blocks, etc.)
17/// that pass HTTP-level health checks but indicate the proxy is unusable
18/// for your target site.
19///
20/// # Example
21/// ```rust,no_run
22/// use reqwest_proxy_pool::{ResponseClassifier, ProxyResponseVerdict};
23///
24/// struct CaptchaDetector;
25///
26/// impl ResponseClassifier for CaptchaDetector {
27///     fn classify(&self, response: &reqwest::Response) -> ProxyResponseVerdict {
28///         // Check status or headers for signs of blocking
29///         if response.status() == 403 {
30///             ProxyResponseVerdict::ProxyBlocked
31///         } else {
32///             ProxyResponseVerdict::Success
33///         }
34///     }
35/// }
36/// ```
37pub trait ResponseClassifier: Send + Sync + 'static {
38    fn classify(&self, response: &reqwest::Response) -> ProxyResponseVerdict;
39}
40
41/// Default classifier: HTTP success = Success, otherwise Passthrough.
42pub struct DefaultResponseClassifier;
43
44impl ResponseClassifier for DefaultResponseClassifier {
45    fn classify(&self, response: &reqwest::Response) -> ProxyResponseVerdict {
46        if response.status().is_success() {
47            ProxyResponseVerdict::Success
48        } else {
49            ProxyResponseVerdict::Passthrough
50        }
51    }
52}