ic_bn_lib_common/traits/
http.rs1use std::{
2 fmt::{self, Debug},
3 hash::Hash,
4};
5
6use async_trait::async_trait;
7use http::Request;
8
9use crate::types::http::{CacheError, Error};
10
11#[cfg_attr(test, mockall::automock)]
13#[async_trait]
14pub trait Client: Send + Sync + fmt::Debug {
15 async fn execute(&self, req: reqwest::Request) -> Result<reqwest::Response, reqwest::Error>;
16}
17
18#[async_trait]
20pub trait ClientHttp<B1, B2 = axum::body::Body>: Send + Sync + fmt::Debug {
21 async fn execute(&self, req: http::Request<B1>) -> Result<http::Response<B2>, Error>;
22}
23
24pub trait KeyExtractor: Clone + Send + Sync + Debug + 'static {
26 type Key: Clone + Send + Sync + Debug + Hash + Eq + 'static;
28
29 fn extract<T>(&self, req: &Request<T>) -> Result<Self::Key, CacheError>;
31}
32
33pub trait CustomBypassReason:
35 Debug + Clone + std::fmt::Display + Into<&'static str> + PartialEq + Eq + Send + Sync + 'static
36{
37}
38
39pub trait Bypasser: Clone + Send + Sync + Debug + 'static {
41 type BypassReason: CustomBypassReason;
43
44 fn bypass<T>(&self, req: &Request<T>) -> Result<Option<Self::BypassReason>, CacheError>;
46}