aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.bleep2
-rw-r--r--pingora-proxy/src/lib.rs19
-rw-r--r--pingora-proxy/src/proxy_trait.rs5
3 files changed, 23 insertions, 3 deletions
diff --git a/.bleep b/.bleep
index bc889d8..60fce0d 100644
--- a/.bleep
+++ b/.bleep
@@ -1 +1 @@
-0195d63b6a8053fa3cf702f670b06067ae81bf6a \ No newline at end of file
+72328c4a1aec58a40b70f82d1144f70c9a19f207 \ No newline at end of file
diff --git a/pingora-proxy/src/lib.rs b/pingora-proxy/src/lib.rs
index 0add56a..d89cb4a 100644
--- a/pingora-proxy/src/lib.rs
+++ b/pingora-proxy/src/lib.rs
@@ -110,6 +110,14 @@ impl<SV> HttpProxy<SV> {
}
}
+ fn handle_init_modules(&mut self)
+ where
+ SV: ProxyHttp,
+ {
+ self.inner
+ .init_downstream_modules(&mut self.downstream_modules);
+ }
+
async fn handle_new_request(
&self,
mut downstream_session: Box<HttpSession>,
@@ -739,7 +747,10 @@ use pingora_core::services::listening::Service;
/// Create a [Service] from the user implemented [ProxyHttp].
///
/// The returned [Service] can be hosted by a [pingora_core::server::Server] directly.
-pub fn http_proxy_service<SV>(conf: &Arc<ServerConf>, inner: SV) -> Service<HttpProxy<SV>> {
+pub fn http_proxy_service<SV>(conf: &Arc<ServerConf>, inner: SV) -> Service<HttpProxy<SV>>
+where
+ SV: ProxyHttp,
+{
http_proxy_service_with_name(conf, inner, "Pingora HTTP Proxy Service")
}
@@ -750,11 +761,15 @@ pub fn http_proxy_service_with_name<SV>(
conf: &Arc<ServerConf>,
inner: SV,
name: &str,
-) -> Service<HttpProxy<SV>> {
+) -> Service<HttpProxy<SV>>
+where
+ SV: ProxyHttp,
+{
let mut proxy = HttpProxy::new(inner, conf.clone());
// Add disabled downstream compression module by default
proxy
.downstream_modules
.add_module(ResponseCompressionBuilder::enable(0));
+ proxy.handle_init_modules();
Service::new(name.to_string(), proxy)
}
diff --git a/pingora-proxy/src/proxy_trait.rs b/pingora-proxy/src/proxy_trait.rs
index 6f429ac..3b83fda 100644
--- a/pingora-proxy/src/proxy_trait.rs
+++ b/pingora-proxy/src/proxy_trait.rs
@@ -40,6 +40,11 @@ pub trait ProxyHttp {
ctx: &mut Self::CTX,
) -> Result<Box<HttpPeer>>;
+ /// Set up downstream modules.
+ ///
+ /// In this phase, users can add or configure modules before the server starts up.
+ fn init_downstream_modules(&self, _modules: &mut HttpModules) {}
+
/// Handle the incoming request.
///
/// In this phase, users can parse, validate, rate limit, perform access control and/or