diff --git a/lychee-lib/src/chain/mod.rs b/lychee-lib/src/chain/mod.rs index 6935275..59ea75c 100644 --- a/lychee-lib/src/chain/mod.rs +++ b/lychee-lib/src/chain/mod.rs @@ -3,11 +3,11 @@ //! lychee is based on a chain of responsibility, where each handler can modify //! a request and decide if it should be passed to the next element or not. //! -//! The chain is implemented as a vector of [`Chainable`] handlers. It is +//! The chain is implemented as a vector of [`Handler`] handlers. It is //! traversed by calling [`Chain::traverse`], which will call -//! [`Chainable::chain`] on each handler in the chain consecutively. +//! [`Handler::chain`] on each handler in the chain consecutively. //! -//! To add external handlers, you can implement the [`Chainable`] trait and add +//! To add external handlers, you can implement the [`Handler`] trait and add //! the handler to the chain. //! //! [pattern]: https://github.com/lpxxn/rust-design-pattern/blob/master/behavioral/chain_of_responsibility.rs @@ -44,10 +44,10 @@ pub(crate) type RequestChain = Chain; /// This holds all handlers, which were chained together. /// Handlers are traversed in order. /// -/// Each handler needs to implement the `Chainable` trait and be `Send`, because +/// Each handler needs to implement the `Handler` trait and be `Send`, because /// the chain is traversed concurrently and the handlers can be sent between /// threads. -pub(crate) type InnerChain = Vec + Send>>; +pub(crate) type InnerChain = Vec + Send>>; /// The outer chain type. /// @@ -99,7 +99,7 @@ impl Chain { } } -/// Chainable trait for implementing request handlers +/// Handler trait for implementing request handlers /// /// This trait needs to be implemented by all chainable handlers. /// It is the only requirement to handle requests in lychee. @@ -112,7 +112,7 @@ impl Chain { /// handler. This allows for modifying the request, such as adding headers or /// changing the URL (e.g. for remapping or filtering). #[async_trait] -pub trait Chainable: Debug { +pub trait Handler: Debug { /// Given an input request, return a [`ChainResult`] to continue or stop the /// chain. /// @@ -122,7 +122,7 @@ pub trait Chainable: Debug { /// # Example /// /// ``` - /// use lychee_lib::{Chainable, ChainResult, Status}; + /// use lychee_lib::{Handler, ChainResult, Status}; /// use reqwest::Request; /// use async_trait::async_trait; /// @@ -130,7 +130,7 @@ pub trait Chainable: Debug { /// struct AddHeader; /// /// #[async_trait] - /// impl Chainable for AddHeader { + /// impl Handler for AddHeader { /// async fn chain(&mut self, mut request: Request) -> ChainResult { /// // You can modify the request however you like here /// request.headers_mut().append("X-Header", "value".parse().unwrap()); @@ -183,7 +183,7 @@ mod test { use super::{ ChainResult, ChainResult::{Done, Next}, - Chainable, + Handler, }; use async_trait::async_trait; @@ -194,7 +194,7 @@ mod test { struct Result(usize); #[async_trait] - impl Chainable for Add { + impl Handler for Add { async fn chain(&mut self, req: Result) -> ChainResult { let added = req.0 + self.0; if added > 100 { diff --git a/lychee-lib/src/checker.rs b/lychee-lib/src/checker.rs index 695c00f..ba89c1c 100644 --- a/lychee-lib/src/checker.rs +++ b/lychee-lib/src/checker.rs @@ -1,5 +1,5 @@ use crate::{ - chain::{ChainResult, Chainable}, + chain::{ChainResult, Handler}, retry::RetryExt, Status, }; @@ -73,7 +73,7 @@ fn clone_unwrap(request: &Request) -> Request { } #[async_trait] -impl Chainable for Checker { +impl Handler for Checker { async fn chain(&mut self, input: Request) -> ChainResult { ChainResult::Done(self.retry_request(input).await) } diff --git a/lychee-lib/src/client.rs b/lychee-lib/src/client.rs index 0bbc422..15f9397 100644 --- a/lychee-lib/src/client.rs +++ b/lychee-lib/src/client.rs @@ -750,7 +750,7 @@ mod tests { use super::ClientBuilder; use crate::{ - chain::{ChainResult, Chainable, RequestChain}, + chain::{ChainResult, Handler, RequestChain}, mock_server, test_utils::get_mock_client_response, Request, Status, Uri, @@ -1086,7 +1086,7 @@ mod tests { struct ExampleHandler(); #[async_trait] - impl Chainable for ExampleHandler { + impl Handler for ExampleHandler { async fn chain(&mut self, _: Request) -> ChainResult { ChainResult::Done(Status::Excluded) } diff --git a/lychee-lib/src/lib.rs b/lychee-lib/src/lib.rs index 272bd78..98a0701 100644 --- a/lychee-lib/src/lib.rs +++ b/lychee-lib/src/lib.rs @@ -85,8 +85,8 @@ use openssl_sys as _; // required for vendored-openssl feature #[doc(inline)] pub use crate::{ basic_auth::BasicAuthExtractor, - // Expose the `Chainable` trait to allow defining external handlers (plugins) - chain::{ChainResult, Chainable}, + // Expose the `Handler` trait to allow defining external handlers (plugins) + chain::{ChainResult, Handler}, // Constants get exposed so that the CLI can use the same defaults as the library client::{ check, Client, ClientBuilder, DEFAULT_MAX_REDIRECTS, DEFAULT_MAX_RETRIES, diff --git a/lychee-lib/src/quirks/mod.rs b/lychee-lib/src/quirks/mod.rs index 333b921..69976fc 100644 --- a/lychee-lib/src/quirks/mod.rs +++ b/lychee-lib/src/quirks/mod.rs @@ -1,5 +1,5 @@ use crate::{ - chain::{ChainResult, Chainable}, + chain::{ChainResult, Handler}, Status, }; use async_trait::async_trait; @@ -92,7 +92,7 @@ impl Quirks { } #[async_trait] -impl Chainable for Quirks { +impl Handler for Quirks { async fn chain(&mut self, input: Request) -> ChainResult { ChainResult::Next(self.apply(input)) } diff --git a/lychee-lib/src/types/basic_auth/credentials.rs b/lychee-lib/src/types/basic_auth/credentials.rs index 906357f..74a4531 100644 --- a/lychee-lib/src/types/basic_auth/credentials.rs +++ b/lychee-lib/src/types/basic_auth/credentials.rs @@ -8,7 +8,7 @@ use reqwest::Request; use serde::Deserialize; use thiserror::Error; -use crate::chain::{ChainResult, Chainable}; +use crate::chain::{ChainResult, Handler}; use crate::Status; #[derive(Copy, Clone, Debug, Error, PartialEq)] @@ -75,7 +75,7 @@ impl BasicAuthCredentials { } #[async_trait] -impl Chainable for Option { +impl Handler for Option { async fn chain(&mut self, mut request: Request) -> ChainResult { if let Some(credentials) = self { request