caelix_core/
interceptor.rs1use crate::{BoxFuture, HttpResponse, RequestContext, Result};
2
3pub struct Next<'a> {
5 inner: Box<dyn FnOnce() -> BoxFuture<'a, Result<HttpResponse>> + Send + 'a>,
6}
7
8impl<'a> Next<'a> {
9 pub fn new(f: impl FnOnce() -> BoxFuture<'a, Result<HttpResponse>> + Send + 'a) -> Self {
11 Self { inner: Box::new(f) }
12 }
13
14 pub fn run(self) -> BoxFuture<'a, Result<HttpResponse>> {
16 (self.inner)()
17 }
18}
19
20pub trait Interceptor: Send + Sync + 'static {
22 fn intercept<'a>(
24 &'a self,
25 ctx: &'a RequestContext,
26 next: Next<'a>,
27 ) -> BoxFuture<'a, Result<HttpResponse>>;
28}