cardinal_proxy/
context_provider.rs1use crate::pingora::{BError, Error};
2use crate::req::ReqCtx;
3use crate::HealthCheckStatus;
4use bytes::Bytes;
5use cardinal_base::context::CardinalContext;
6use pingora::proxy::Session;
7use std::sync::Arc;
8use std::time::Duration;
9
10#[async_trait::async_trait]
11pub trait CardinalContextProvider: Send + Sync {
12 fn ctx(&self) -> ReqCtx {
13 ReqCtx::default()
14 }
15
16 fn resolve(&self, session: &Session, ctx: &mut ReqCtx) -> Option<Arc<CardinalContext>>;
17 fn health_check(&self, _session: &Session) -> HealthCheckStatus {
18 HealthCheckStatus::None
19 }
20
21 fn logging(&self, _session: &mut Session, _e: Option<&Error>, _ctx: &mut ReqCtx) {}
22
23 async fn request_body_filter(
24 &self,
25 _session: &mut Session,
26 _body: &mut Option<Bytes>,
27 _end_of_stream: bool,
28 _ctx: &mut ReqCtx,
29 ) -> crate::pingora::Result<()> {
30 Ok(())
31 }
32
33 fn response_body_filter(
34 &self,
35 _session: &mut Session,
36 _body: &mut Option<Bytes>,
37 _end_of_stream: bool,
38 _ctx: &mut ReqCtx,
39 ) -> crate::pingora::Result<Option<Duration>> {
40 Ok(None)
41 }
42
43 async fn early_request_filter(
44 &self,
45 _session: &mut Session,
46 _ctx: &mut ReqCtx,
47 ) -> Result<(), BError>
48 where
49 Self: Send + Sync,
50 {
51 Ok(())
52 }
53}