Skip to main content

WebsiteChecker

Struct WebsiteChecker 

Source
pub(crate) struct WebsiteChecker {
    method: Method,
    github_client: Option<Octocrab>,
    plugin_request_chain: RequestChain,
    max_retries: u64,
    retry_wait_time: Duration,
    accepted: HashSet<StatusCode>,
    require_https: bool,
    include_fragments: bool,
    fragment_checker: FragmentChecker,
    redirect_history: RedirectHistory,
    host_pool: Arc<HostPool>,
}

Fields§

§method: Method

Request method used for making requests.

§github_client: Option<Octocrab>

GitHub client used for requests.

§plugin_request_chain: RequestChain

The chain of plugins to be executed on each request.

§max_retries: u64

Maximum number of retries per request before returning an error.

§retry_wait_time: Duration

Initial wait time between retries of failed requests. This doubles after each failure.

§accepted: HashSet<StatusCode>

Set of accepted return codes / status codes.

Unmatched return codes/ status codes are deemed as errors.

§require_https: bool

Requires using HTTPS when it’s available.

This would treat unencrypted links as errors when HTTPS is available.

§include_fragments: bool

Whether to check the existence of fragments in the response HTML files.

Will be disabled if the request method is HEAD.

§fragment_checker: FragmentChecker

Utility for performing fragment checks in HTML files.

§redirect_history: RedirectHistory

Keep track of HTTP redirections for reporting

§host_pool: Arc<HostPool>

Optional host pool for per-host rate limiting.

When present, HTTP requests will be routed through this pool for rate limiting. When None, requests go directly through reqwest_client.

Implementations§

Source§

impl WebsiteChecker

Source

pub(crate) fn host_pool(&self) -> Arc<HostPool>

Get a reference to HostPool

Source

pub(crate) fn new( method: Method, retry_wait_time: Duration, redirect_history: RedirectHistory, max_retries: u64, accepted: HashSet<StatusCode>, github_client: Option<Octocrab>, require_https: bool, plugin_request_chain: RequestChain, include_fragments: bool, host_pool: Arc<HostPool>, ) -> Self

Source

pub(crate) async fn retry_request(&self, request: Request) -> Status

Retry requests up to max_retries times with an exponential backoff. Note that, in addition, there also is a host-specific backoff when host-specific rate limiting or errors are detected.

Source

async fn check_default(&self, request: Request) -> Status

Check a URI using reqwest.

Source

async fn check_html_fragment( &self, url: Url, status: Status, content: &str, file_type: FileType, ) -> Status

Source

pub(crate) async fn check_website( &self, uri: &Uri, credentials: Option<BasicAuthCredentials>, ) -> Result<Status, ErrorKind>

Checks the given URI of a website.

§Errors

This returns an Err if

  • The URI is invalid.
  • The request failed.
  • The response status code is not accepted.
  • The URI cannot be converted to HTTPS.
Source

async fn handle_insecure_url( &self, uri: &Uri, default_chain: &Chain<Request, Status>, status: Status, ) -> Result<Status, ErrorKind>

Mark HTTP URLs as insecure, if the user required HTTPS and the URL is available under HTTPS.

Source

async fn check_website_inner( &self, uri: &Uri, default_chain: &RequestChain, ) -> Status

Checks the given URI of a website.

Unsupported schemes will be ignored

Note: we use inner to improve compile times by avoiding monomorphization

§Errors

This returns an Err if

  • The URI is invalid.
  • The request failed.
  • The response status code is not accepted.
Source

async fn handle_github(&self, status: Status, uri: &Uri) -> Status

Source

async fn check_github(&self, uri: GithubUri) -> Status

Check a uri hosted on GitHub via the GitHub API.

§Caveats

Files inside private repositories won’t get checked and instead would be reported as valid if the repository itself is reachable through the API.

A better approach would be to download the file through the API or clone the repo, but we chose the pragmatic approach.

Trait Implementations§

Source§

impl Clone for WebsiteChecker

Source§

fn clone(&self) -> WebsiteChecker

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 WebsiteChecker

Source§

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

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

impl Handler<Request, Status> for WebsiteChecker

Source§

fn handle<'life0, 'async_trait>( &'life0 mut self, input: Request, ) -> Pin<Box<dyn Future<Output = ChainResult<Request, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Given an input request, return a ChainResult to continue or stop the chain. 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