use crate::Request;
use crate::Response;
#[allow(unused)]
pub fn before(f: impl Fn(Request) -> Request + Send + Sync + 'static) -> impl Middleware {
create(f, identity)
}
#[allow(unused)]
pub fn after(f: impl Fn(Response) -> Response + Send + Sync + 'static) -> impl Middleware {
create(identity, f)
}
pub fn create(
request: impl Fn(Request) -> Request + Send + Sync + 'static,
response: impl Fn(Response) -> Response + Send + Sync + 'static,
) -> impl Middleware {
struct Impl<F, G>(F, G);
impl<F, G> Middleware for Impl<F, G>
where
F: Fn(Request) -> Request + Send + Sync + 'static,
G: Fn(Response) -> Response + Send + Sync + 'static,
{
fn filter_request(&self, request: Request) -> Request {
(self.0)(request)
}
fn filter_response(&self, response: Response) -> Response {
(self.1)(response)
}
}
Impl(request, response)
}
pub trait Middleware: Send + Sync + 'static {
fn filter_request(&self, request: Request) -> Request {
request
}
fn filter_response(&self, response: Response) -> Response {
response
}
}
const fn identity<T>(t: T) -> T {
t
}