diff options
author | Wladimir Palant <[email protected]> | 2024-06-15 07:26:43 +0000 |
---|---|---|
committer | Edward Wang <[email protected]> | 2024-06-28 12:34:25 -0700 |
commit | dda7bec58cb176228b8194e97c8c9e52bf36b878 (patch) | |
tree | 73f71bc97c0ae9ca47ed2046393dd7b4604eea2f /pingora-proxy | |
parent | 1176af300b870439d37b3493c6876977a8a428d1 (diff) | |
download | pingora-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
Diffstat (limited to 'pingora-proxy')
-rw-r--r-- | pingora-proxy/src/lib.rs | 19 | ||||
-rw-r--r-- | pingora-proxy/src/proxy_trait.rs | 5 |
2 files changed, 22 insertions, 2 deletions
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 |