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