pub struct FetcherConfigBuilder { /* private fields */ }Expand description
Builder for constructing a FetcherConfig with validation.
The builder provides a fluent API for setting configuration options and catches
invalid combinations at build time (e.g., setting both a static proxy and a proxy
rotator). Call build() to get the validated config.
let (config, rotator) = FetcherConfigBuilder::new()
.timeout_secs(10)
.retries(5)
.follow_redirects(FollowRedirects::All)
.build()
.unwrap();Implementations§
Source§impl FetcherConfigBuilder
impl FetcherConfigBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new builder pre-populated with the same defaults as
FetcherConfig::default() – 30s timeout, 3 retries, Chrome impersonation, etc.
Sourcepub fn impersonate(self, imp: Impersonate) -> Self
pub fn impersonate(self, imp: Impersonate) -> Self
Sets the browser impersonation profile. See Impersonate for the available
strategies (none, single browser, or random rotation).
Sourcepub fn stealthy_headers(self, enabled: bool) -> Self
pub fn stealthy_headers(self, enabled: bool) -> Self
Enables or disables stealth header injection. When enabled, the fetcher adds browser-like headers (Referer, Sec-Fetch-*, etc.) to help bypass bot detection.
Sourcepub fn proxy(self, proxy: Proxy) -> Self
pub fn proxy(self, proxy: Proxy) -> Self
Sets a static proxy for all requests. Cannot be combined with
proxy_rotator() – the builder will return an error on
build() if both are set.
Sourcepub fn timeout_secs(self, secs: u64) -> Self
pub fn timeout_secs(self, secs: u64) -> Self
Sets the request timeout in seconds. This covers the entire request lifecycle including DNS, TLS handshake, and body download.
Sourcepub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
Adds a single default header that will be sent with every request.
Call multiple times to add several headers. Per-request headers in
RequestConfig take precedence over these.
Sourcepub fn headers(self, headers: HashMap<String, String>) -> Self
pub fn headers(self, headers: HashMap<String, String>) -> Self
Replaces all default headers with the given map. Any headers previously
added with header() are discarded.
Sourcepub fn retries(self, retries: u32) -> Self
pub fn retries(self, retries: u32) -> Self
Sets the maximum number of retry attempts. A value of 1 means the request is tried once with no retries. The default is 3.
Sourcepub fn retry_delay_secs(self, secs: u64) -> Self
pub fn retry_delay_secs(self, secs: u64) -> Self
Sets the fixed delay in seconds between retries. There is no exponential backoff – each retry waits exactly this long.
Sourcepub fn follow_redirects(self, policy: FollowRedirects) -> Self
pub fn follow_redirects(self, policy: FollowRedirects) -> Self
Sets the redirect-following policy. See FollowRedirects for the options.
Sourcepub fn max_redirects(self, max: usize) -> Self
pub fn max_redirects(self, max: usize) -> Self
Sets the maximum number of redirects to follow. If this limit is exceeded, the request fails with an error rather than looping indefinitely.
Sourcepub fn verify(self, verify: bool) -> Self
pub fn verify(self, verify: bool) -> Self
Enables or disables TLS certificate verification. Disabling this is a security risk and should only be used for testing with self-signed certs.
Sourcepub fn proxy_rotator(self, rotator: ProxyRotator) -> Self
pub fn proxy_rotator(self, rotator: ProxyRotator) -> Self
Sourcepub fn build(self) -> Result<(FetcherConfig, Option<ProxyRotator>)>
pub fn build(self) -> Result<(FetcherConfig, Option<ProxyRotator>)>
Validates and builds the configuration, returning a tuple of the config and an optional proxy rotator. Returns an error if both a static proxy and a proxy rotator were configured, since those options are mutually exclusive.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for FetcherConfigBuilder
impl RefUnwindSafe for FetcherConfigBuilder
impl Send for FetcherConfigBuilder
impl Sync for FetcherConfigBuilder
impl Unpin for FetcherConfigBuilder
impl UnsafeUnpin for FetcherConfigBuilder
impl UnwindSafe for FetcherConfigBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more