pub struct FetchConfigBuilder { /* private fields */ }Expand description
A builder for a custom FetchConfig.
The builder starts from the built-in default policy. Each setter stores its
value as given and returns the builder, so calls can be chained.
FetchConfigBuilder::build checks every value at once and reports the
first invalid one as a ConfigError.
Implementations§
Source§impl FetchConfigBuilder
impl FetchConfigBuilder
Sourcepub fn allow_http(self, yes: bool) -> FetchConfigBuilder
pub fn allow_http(self, yes: bool) -> FetchConfigBuilder
Sets whether plain http:// URLs are permitted.
Sourcepub fn allow_ports(
self,
ports: impl IntoIterator<Item = u16>,
) -> FetchConfigBuilder
pub fn allow_ports( self, ports: impl IntoIterator<Item = u16>, ) -> FetchConfigBuilder
Replaces the set of ports a fetch may target.
Sourcepub fn allow_ip_literals(self, yes: bool) -> FetchConfigBuilder
pub fn allow_ip_literals(self, yes: bool) -> FetchConfigBuilder
Sets whether a URL may give its host as a bare IP address.
This lifts only the syntax rule. The address itself is still checked against the blocked ranges. A loopback, private, link-local, or other non-global address stays blocked unless an exact host-and-address exception allows it.
Sourcepub fn deny_cidr(self, cidr: impl Into<String>) -> FetchConfigBuilder
pub fn deny_cidr(self, cidr: impl Into<String>) -> FetchConfigBuilder
Adds a CIDR range to block, on top of the built-in blocked ranges.
build parses the text and reports a range that fails to parse.
Sourcepub fn allow_host_address(
self,
host: impl Into<String>,
addr: IpAddr,
) -> FetchConfigBuilder
pub fn allow_host_address( self, host: impl Into<String>, addr: IpAddr, ) -> FetchConfigBuilder
Adds an exception that lets one host reach one otherwise-blocked address.
The exception applies only when a fetch to host connects to addr.
Another host that resolves to addr stays blocked. The host match
ignores case and a trailing dot. build checks that host is a valid
domain name or IP address. This is the only supported way to reach an
otherwise-blocked address.
Sourcepub fn max_redirects(self, n: usize) -> FetchConfigBuilder
pub fn max_redirects(self, n: usize) -> FetchConfigBuilder
Sets the maximum number of redirect hops a single fetch may follow.
Sourcepub fn max_bytes(self, n: usize) -> FetchConfigBuilder
pub fn max_bytes(self, n: usize) -> FetchConfigBuilder
Sets the largest response body accepted, in decompressed bytes.
Sourcepub fn max_chars(self, n: usize) -> FetchConfigBuilder
pub fn max_chars(self, n: usize) -> FetchConfigBuilder
Sets the ceiling on returned text length, in characters.
Sourcepub fn connect_timeout(self, d: Duration) -> FetchConfigBuilder
pub fn connect_timeout(self, d: Duration) -> FetchConfigBuilder
Sets the time allowed to open a TCP connection, on every redirect hop.
Sourcepub fn timeout(self, d: Duration) -> FetchConfigBuilder
pub fn timeout(self, d: Duration) -> FetchConfigBuilder
Sets the cap on the total time a single request may take.
Sourcepub fn pool_idle_timeout(self, d: Duration) -> FetchConfigBuilder
pub fn pool_idle_timeout(self, d: Duration) -> FetchConfigBuilder
Sets how long an idle pooled connection is kept before it is closed.
Sourcepub fn user_agent(self, ua: impl Into<String>) -> FetchConfigBuilder
pub fn user_agent(self, ua: impl Into<String>) -> FetchConfigBuilder
Sets the User-Agent header sent on every request.
Sourcepub fn build(self) -> Result<FetchConfig, ConfigError>
pub fn build(self) -> Result<FetchConfig, ConfigError>
Checks every value and returns the finished FetchConfig.
§Errors
Returns ConfigError for the first invalid value it finds:
- a
User-Agentthat is not a legal HTTP header value; - a
max_bytesof zero or above 64 MiB; - a
max_charsof zero or above 10,000,000; - a
max_redirectsabove 20; - a
connect_timeoutof zero or above 60 seconds; - a
timeoutof zero or above 300 seconds; - a
pool_idle_timeoutof zero or above 600 seconds; - a denied CIDR range that fails to parse;
- an exception host that is not a valid domain name or IP address.
Trait Implementations§
Source§impl Clone for FetchConfigBuilder
impl Clone for FetchConfigBuilder
Source§fn clone(&self) -> FetchConfigBuilder
fn clone(&self) -> FetchConfigBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FetchConfigBuilder
impl Debug for FetchConfigBuilder
Source§impl Default for FetchConfigBuilder
impl Default for FetchConfigBuilder
Source§fn default() -> FetchConfigBuilder
fn default() -> FetchConfigBuilder
Auto Trait Implementations§
impl Freeze for FetchConfigBuilder
impl RefUnwindSafe for FetchConfigBuilder
impl Send for FetchConfigBuilder
impl Sync for FetchConfigBuilder
impl Unpin for FetchConfigBuilder
impl UnsafeUnpin for FetchConfigBuilder
impl UnwindSafe for FetchConfigBuilder
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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