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§
- archive
- Check online archives to try and restore broken links
- 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§
- Accept
Range AcceptRangespecifies which HTTP status codes are accepted and considered successful when checking a remote URL.- Basic
Auth Credentials BasicAuthCredentialscontains a pair of basic auth values consisting of a username and password.- Basic
Auth Extractor - Extracts basic auth credentials from a given URI.
Credentials are extracted if the URI matches one of the provided
BasicAuthSelectorinstances. - Basic
Auth Selector BasicAuthSelectorprovides 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.
- Client
Builder - Builder for
Client. - Collector
- Collector keeps the state of link collection It drives the link extraction from inputs
- Cookie
Jar - A wrapper around
reqwest_cookie_store::CookieStore - File
Extensions - Represents an ordered list of file extensions.
- Filter
- A generic URI filter Used to decide if a given URI should be checked or skipped
- Input
- Lychee Input with optional file hint for parsing
- Input
Content - Encapsulates the content for a given input
- Input
Resolver - Resolves input sources into concrete, processable sources.
- Redirects
- A list of URLs that were followed through HTTP redirects, starting from the original URL and ending at the final destination. Each entry in the list represents a step in the redirect sequence.
- Request
- A request type that can be handle by lychee
- Response
- Response type returned by lychee after checking a URI
- Response
Body - Encapsulates the state of a URI check
- Status
Code Excluder - A
StatusCodeExcluderholds 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.StatusCodeExcluderdiffers fromStatusCodeSelectorin the defaults it provides. As this is meant to exclude status codes, the default is to keep everything. - Status
Code Selector - A
StatusCodeSelectorholds 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.StatusCodeSelectordiffers fromStatusCodeExcluderin 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§
- Accept
Range Error - Indicates that the parsing process of an
AcceptRangefrom 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.
- Cache
Status - 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.
- Chain
Result - Result of a handler.
- Error
Kind - Kinds of status errors Note: The error messages can change over time, so don’t match on the output
- File
Type FileTypedefines which file types lychee can handle- Input
Source - Input types which lychee supports
- Resolved
Input Source - Resolved input sources that can be processed for content.
- 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.