aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorWladimir Palant <[email protected]>2024-06-15 07:26:43 +0000
committerEdward Wang <[email protected]>2024-06-28 12:34:25 -0700
commitdda7bec58cb176228b8194e97c8c9e52bf36b878 (patch)
tree73f71bc97c0ae9ca47ed2046393dd7b4604eea2f
parent1176af300b870439d37b3493c6876977a8a428d1 (diff)
downloadpingora-dda7bec58cb176228b8194e97c8c9e52bf36b878.tar.gz
pingora-dda7bec58cb176228b8194e97c8c9e52bf36b878.zip
Added `init_downstream_modules` phase allowing modules to be set up before startup
Includes-commit: 1bf3d4dfea191cdcefd37dc42fa5c269fc29ff64 Replicated-from: https://github.com/cloudflare/pingora/pull/284
-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