use anyhow::Result;
use async_trait::async_trait;
use oauth2::Oauth2;
use once_cell::sync::Lazy;
use pingora_proxy::Session;
use crate::{config::RoutePlugin, proxy_server::https_proxy::RouterContext};
pub mod jwt;
pub mod oauth2;
pub(crate) struct ProxyPlugins {
pub oauth2: Lazy<Oauth2>,
}
pub static PLUGINS: Lazy<ProxyPlugins> = Lazy::new(|| ProxyPlugins {
oauth2: Lazy::new(Oauth2::new),
});
#[async_trait]
pub trait MiddlewarePlugin {
async fn request_filter(
&self,
session: &mut Session,
state: &RouterContext,
config: &RoutePlugin,
) -> Result<bool>;
async fn response_filter(
&self,
session: &mut Session,
state: &RouterContext,
config: &RoutePlugin,
) -> Result<bool>;
}