Skip to main content

ClientBuilder

Struct ClientBuilder 

Source
pub struct ClientBuilder {
Show 30 fields github_token: Option<SecretString>, remaps: Option<Remaps>, fallback_extensions: Vec<String>, index_files: Option<Vec<String>>, includes: Option<RegexSet>, excludes: Option<RegexSet>, exclude_all_private: bool, exclude_private_ips: bool, exclude_link_local_ips: bool, exclude_loopback_ips: bool, include_mail: bool, max_redirects: usize, max_retries: u64, min_tls_version: Option<Version>, user_agent: String, allow_insecure: bool, schemes: HashSet<String>, custom_headers: HeaderMap, method: Method, accepted: HashSet<StatusCode>, timeout: Option<Duration>, base: Option<Base>, retry_wait_time: Duration, require_https: bool, cookie_jar: Option<Arc<CookieStoreMutex>>, include_fragments: bool, include_wikilinks: bool, plugin_request_chain: RequestChain, rate_limit_config: RateLimitConfig, hosts: HostConfigs,
}
Expand description

Builder for Client.

See crate-level documentation for usage example.

Fields§

§github_token: Option<SecretString>

Optional GitHub token used for GitHub links.

This allows much more request before getting rate-limited.

§Rate-limiting Defaults

As of Feb 2022, it’s 60 per hour without GitHub token v.s. 5000 per hour with token.

§remaps: Option<Remaps>

Remap URIs matching a pattern to a different URI.

This makes it possible to remap any HTTP/HTTPS endpoint to a different HTTP/HTTPS one. This feature could also be used to proxy certain requests.

§Usage Notes

Use with caution because a large set of remapping rules may cause performance issues.

Furthermore rules are executed sequentially and multiple mappings for the same URI are allowed, so it is up to the library user’s discretion to make sure rules don’t conflict with each other.

§fallback_extensions: Vec<String>

Automatically append file extensions to file:// URIs as needed

This option takes effect on file:// URIs which do not exist.

§index_files: Option<Vec<String>>

Index file names to use when resolving file:// URIs which point to directories.

For local directory links, if this is non-None, then at least one index file from this list must exist in order for the link to be considered valid. Index files names are required to match regular files, aside from the special . name which will match the directory itself.

If None, index file checking is disabled and directory links are valid as long as the directory exists on disk.

In the ClientBuilder, this defaults to None.

§includes: Option<RegexSet>

Links matching this set of regular expressions are always checked.

This has higher precedence over ClientBuilder::excludes, but has lower precedence compared to any other exclude_ fields or ClientBuilder::schemes below.

§excludes: Option<RegexSet>

Links matching this set of regular expressions are ignored, except when a link also matches against ClientBuilder::includes.

§exclude_all_private: bool

When true, exclude all private network addresses.

This effectively turns on the following fields:

§exclude_private_ips: bool

When true, exclude private IP addresses.

§IPv4

The private address ranges are defined in IETF RFC 1918 and include:

  • 10.0.0.0/8
  • 172.16.0.0/12
  • 192.168.0.0/16

§IPv6

The address is a unique local address (fc00::/7).

This property is defined in IETF RFC 4193.

§Note

Unicast site-local network was defined in IETF RFC 4291, but was fully deprecated in IETF RFC 3879. So it is NOT considered as private on this purpose.

§exclude_link_local_ips: bool

When true, exclude link-local IPs.

§IPv4

The address is 169.254.0.0/16.

This property is defined by IETF RFC 3927.

§IPv6

The address is a unicast address with link-local scope, as defined in RFC 4291.

A unicast address has link-local scope if it has the prefix fe80::/10, as per RFC 4291 section 2.4.

§exclude_loopback_ips: bool

When true, exclude loopback IP addresses.

§IPv4

This is a loopback address (127.0.0.0/8).

This property is defined by IETF RFC 1122.

§IPv6

This is the loopback address (::1), as defined in IETF RFC 4291 section 2.5.3.

§include_mail: bool

When true, check mail addresses.

§max_redirects: usize

Maximum number of redirects per request before returning an error.

Defaults to DEFAULT_MAX_REDIRECTS.

§max_retries: u64

Maximum number of retries per request before returning an error.

Defaults to DEFAULT_MAX_RETRIES.

§min_tls_version: Option<Version>

Minimum accepted TLS version.

§user_agent: String

User-agent used for checking links.

Defaults to DEFAULT_USER_AGENT.

§Notes

This may be helpful for bypassing certain firewalls.

§allow_insecure: bool

When true, accept invalid SSL certificates.

§Warning

You should think very carefully before allowing invalid SSL certificates. It will accept any certificate for any site to be trusted including expired certificates. This introduces significant vulnerabilities, and should only be used as a last resort.

§schemes: HashSet<String>

Set of accepted URL schemes.

Only links with matched URI schemes are checked. This has no effect when it’s empty.

§custom_headers: HeaderMap

Default headers for every request.

This allows working around validation issues on some websites. See also here for usage examples.

§method: Method

HTTP method used for requests, e.g. GET or HEAD.

§accepted: HashSet<StatusCode>

Set of accepted return codes / status codes.

Unmatched return codes/ status codes are deemed as errors.

§timeout: Option<Duration>

Response timeout per request.

§base: Option<Base>

Base for resolving paths.

E.g. if the base is /home/user/ and the path is file.txt, the resolved path would be /home/user/file.txt.

§retry_wait_time: Duration

Initial time between retries of failed requests.

Defaults to DEFAULT_RETRY_WAIT_TIME_SECS.

§Notes

For each request, the wait time increases using an exponential backoff mechanism. For example, if the value is 1 second, then it waits for 2 ^ (N-1) seconds before the N-th retry.

This prevents spending too much system resources on slow responders and prioritizes other requests.

§require_https: bool

When true, requires using HTTPS when it’s available.

This would treat unencrypted links as errors when HTTPS is available. It has no effect on non-HTTP schemes or if the URL doesn’t support HTTPS.

§cookie_jar: Option<Arc<CookieStoreMutex>>§include_fragments: bool

Enable the checking of fragments in links.

§include_wikilinks: bool

Enable the checking of wikilinks in markdown files. Note that base must not be None if you set this true.

§plugin_request_chain: RequestChain

Requests run through this chain where each item in the chain can modify the request. A chained item can also decide to exit early and return a status, so that subsequent chain items are skipped and the lychee-internal request chain is not activated.

§rate_limit_config: RateLimitConfig

Global rate limiting configuration that applies as defaults to all hosts

§hosts: HostConfigs

Per-host configuration overrides

Implementations§

Source§

impl ClientBuilder

Source

pub fn builder() -> ClientBuilderBuilder<((), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ())>

Create a builder for building ClientBuilder. On the builder, call .github_token(...)(optional), .remaps(...)(optional), .fallback_extensions(...)(optional), .index_files(...)(optional), .includes(...)(optional), .excludes(...)(optional), .exclude_all_private(...)(optional), .exclude_private_ips(...)(optional), .exclude_link_local_ips(...)(optional), .exclude_loopback_ips(...)(optional), .include_mail(...)(optional), .max_redirects(...)(optional), .max_retries(...)(optional), .min_tls_version(...)(optional), .user_agent(...)(optional), .allow_insecure(...)(optional), .schemes(...)(optional), .custom_headers(...)(optional), .method(...)(optional), .accepted(...)(optional), .timeout(...)(optional), .base(...)(optional), .retry_wait_time(...)(optional), .require_https(...)(optional), .cookie_jar(...)(optional), .include_fragments(...)(optional), .include_wikilinks(...)(optional), .plugin_request_chain(...)(optional), .rate_limit_config(...)(optional), .hosts(...)(optional) to set the values of the fields. Finally, call .build() to create the instance of ClientBuilder.

Source§

impl ClientBuilder

Source

pub fn client(self) -> Result<Client>

Instantiates a Client.

§Errors

Returns an Err if:

  • The user-agent contains characters other than ASCII 32-127.
  • The reqwest client cannot be instantiated. This occurs if a TLS backend cannot be initialized or the resolver fails to load the system configuration. See here.
  • The GitHub client cannot be created. Since the implementation also uses reqwest under the hood, this errors in the same circumstances as the last one.
Source

fn build_host_clients( &self, redirect_history: &RedirectHistory, ) -> Result<ClientMap>

Build the host-specific clients with their host-specific headers

Source

fn build_client( &self, redirect_history: &RedirectHistory, ) -> Result<ClientBuilder>

Create a reqwest::ClientBuilder based on various fields

Source

fn default_headers(&self) -> Result<HeaderMap>

Trait Implementations§

Source§

impl Clone for ClientBuilder

Source§

fn clone(&self) -> ClientBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ClientBuilder

Source§

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

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

impl Default for ClientBuilder

Source§

fn default() -> Self

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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
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

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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