Crate lychee_lib

Source
Expand description

lychee-lib is the library component of lychee, and is used for checking links.

“Hello world” example:

use lychee_lib::Result;

#[tokio::main]
async fn main() -> Result<()> {
  let response = lychee_lib::check("https://github.com/lycheeverse/lychee").await?;
  println!("{response}");
  Ok(())
}

For more specific use-cases you can build a lychee client yourself, using the ClientBuilder which can be used to configure and run your own link checker and grants full flexibility:

use lychee_lib::{ClientBuilder, Result, Status};

#[tokio::main]
async fn main() -> Result<()> {
  let client = ClientBuilder::default().client()?;
  let response = client.check("https://github.com/lycheeverse/lychee").await?;
  assert!(response.status().is_success());
  Ok(())
}

Modules§

chain
Chain of responsibility pattern implementation.
collector
A pool of clients, to handle concurrent checks
extract
Functionality to extract URIs from inputs
filter
Filters are a way to define behavior when encountering URIs that need to be treated differently, such as local IPs or e-mail addresses
remap
Remapping rules which allow to map URLs matching a pattern to a different URL.

Structs§

AcceptRange
AcceptRange specifies which HTTP status codes are accepted and considered successful when checking a remote URL.
BasicAuthCredentials
BasicAuthCredentials contains a pair of basic auth values consisting of a username and password.
BasicAuthExtractor
Extracts basic auth credentials from a given URI. Credentials are extracted if the URI matches one of the provided BasicAuthSelector instances.
BasicAuthSelector
BasicAuthSelector provides basic auth credentials for URLs which match the specified regex. This allows users to set different credentials based on the URLs they want to target.
Client
Handles incoming requests and returns responses.
ClientBuilder
Builder for Client.
Collector
Collector keeps the state of link collection It drives the link extraction from inputs
CookieJar
A wrapper around reqwest_cookie_store::CookieStore
Excludes
Exclude configuration for the link checker. You can ignore links based on regex patterns.
Filter
A generic URI filter Used to decide if a given URI should be checked or skipped
Includes
Include configuration for the link checker. You can include links based on regex patterns
Input
Lychee Input with optional file hint for parsing
InputContent
Encapsulates the content for a given input
Request
A request type that can be handle by lychee
Response
Response type returned by lychee after checking a URI
ResponseBody
Encapsulates the state of a URI check
StatusCodeExcluder
A StatusCodeExcluder holds ranges of HTTP status codes, and determines whether a specific code is matched, so the link can be counted as valid (not broken) or excluded. StatusCodeExcluder differs from StatusCodeSelector in the defaults it provides. As this is meant to exclude status codes, the default is to keep everything.
StatusCodeSelector
A StatusCodeSelector holds ranges of HTTP status codes, and determines whether a specific code is matched, so the link can be counted as valid (not broken) or excluded. StatusCodeSelector differs from StatusCodeExcluder in the defaults it provides. As this is meant to select valid status codes, the default includes every successful status.
Uri
Lychee’s own representation of a URI, which encapsulates all supported formats.

Enums§

AcceptRangeError
Indicates that the parsing process of an AcceptRange from a string failed due to various underlying reasons.
Base
When encountering links without a full domain in a document, the base determines where this resource can be found. Both, local and remote targets are supported.
CacheStatus
Representation of the status of a cached request. This is kept simple on purpose because the type gets serialized to a cache file and might need to be parsed by other tools or edited by humans.
ChainResult
Result of a handler.
ErrorKind
Kinds of status errors Note: The error messages can change over time, so don’t match on the output
FileType
FileType defines which file types lychee can handle
InputSource
Input types which lychee supports
Status
Response status of the request.

Constants§

DEFAULT_MAX_REDIRECTS
Default number of redirects before a request is deemed as failed, 5.
DEFAULT_MAX_RETRIES
Default number of retries before a request is deemed as failed, 3.
DEFAULT_RETRY_WAIT_TIME_SECS
Default wait time in seconds between retries, 1.
DEFAULT_TIMEOUT_SECS
Default timeout in seconds before a request is deemed as failed, 20.
DEFAULT_USER_AGENT
Default user agent, lychee-<PKG_VERSION>.

Traits§

Handler
Handler trait for implementing request handlers

Functions§

check
A shorthand function to check a single URI.

Type Aliases§

Result
The lychee Result type