mirror of
https://github.com/cloudflare/pingora.git
synced 2024-09-20 02:31:35 +02:00
Added init_downstream_modules
phase allowing modules to be set up before startup
This commit is contained in:
parent
31d7b63ed7
commit
1bf3d4dfea
2 changed files with 22 additions and 2 deletions
|
@ -108,6 +108,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>,
|
||||
|
@ -733,7 +741,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")
|
||||
}
|
||||
|
||||
|
@ -744,11 +755,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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue