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§
- Accept
Range AcceptRange
specifies which HTTP status codes are accepted and considered successful when checking a remote URL.- Basic
Auth Credentials BasicAuthCredentials
contains 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
BasicAuthSelector
instances. - Basic
Auth Selector 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.
- 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
- 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
- Input
Content - 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
- Response
Body - Encapsulates the state of a URI check
- Status
Code Excluder - 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 fromStatusCodeSelector
in the defaults it provides. As this is meant to exclude status codes, the default is to keep everything. - Status
Code Selector - 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 fromStatusCodeExcluder
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§
- Accept
Range Error - 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.
- 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 FileType
defines which file types lychee can handle- Input
Source - 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