Skip to main content

FetchConfigBuilder

Struct FetchConfigBuilder 

Source
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

Source

pub fn allow_http(self, yes: bool) -> FetchConfigBuilder

Sets whether plain http:// URLs are permitted.

Source

pub fn allow_ports( self, ports: impl IntoIterator<Item = u16>, ) -> FetchConfigBuilder

Replaces the set of ports a fetch may target.

Source

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.

Source

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.

Source

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.

Source

pub fn max_redirects(self, n: usize) -> FetchConfigBuilder

Sets the maximum number of redirect hops a single fetch may follow.

Source

pub fn max_bytes(self, n: usize) -> FetchConfigBuilder

Sets the largest response body accepted, in decompressed bytes.

Source

pub fn max_chars(self, n: usize) -> FetchConfigBuilder

Sets the ceiling on returned text length, in characters.

Source

pub fn connect_timeout(self, d: Duration) -> FetchConfigBuilder

Sets the time allowed to open a TCP connection, on every redirect hop.

Source

pub fn timeout(self, d: Duration) -> FetchConfigBuilder

Sets the cap on the total time a single request may take.

Source

pub fn pool_idle_timeout(self, d: Duration) -> FetchConfigBuilder

Sets how long an idle pooled connection is kept before it is closed.

Source

pub fn user_agent(self, ua: impl Into<String>) -> FetchConfigBuilder

Sets the User-Agent header sent on every request.

Source

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-Agent that is not a legal HTTP header value;
  • a max_bytes of zero or above 64 MiB;
  • a max_chars of zero or above 10,000,000;
  • a max_redirects above 20;
  • a connect_timeout of zero or above 60 seconds;
  • a timeout of zero or above 300 seconds;
  • a pool_idle_timeout of 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

Source§

fn clone(&self) -> FetchConfigBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FetchConfigBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FetchConfigBuilder

Source§

fn default() -> FetchConfigBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSync for T
where T: Sync,

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more