spider_downloader/traits.rs
1//! Core downloader traits.
2
3pub use spider_util::http_client::HttpClient;
4pub use spider_util::request::Request;
5pub use spider_util::response::Response;
6
7use async_trait::async_trait;
8use spider_util::error::SpiderError;
9
10/// Trait implemented by HTTP downloaders used by the crawler runtime.
11#[async_trait]
12pub trait Downloader: Send + Sync + 'static {
13 /// Concrete HTTP client type used by the downloader.
14 type Client: Send + Sync;
15
16 /// Executes the HTTP transaction for a request.
17 ///
18 /// # Errors
19 ///
20 /// Returns an error when request execution fails.
21 async fn download(&self, request: Request) -> Result<Response, SpiderError>;
22
23 /// Returns the underlying client value used by this downloader.
24 fn client(&self) -> &Self::Client;
25}