cloudflare / pingora

A library for building fast, reliable and evolvable network services.
Apache License 2.0
20.21k stars 1.1k forks source link

Added `init_downstream_modules` phase allowing modules to be set up before startup #284

Closed palant closed 1 day ago

palant commented 2 weeks ago

This addresses a roadblock I’ve hit trying to make the new downstream modules mechanism work for me: these cannot be configured from within the HttpProxy instance. The configuration has to happen after http_proxy_service has been called, but at this point the HttpProxy instance has been moved into the service and is no longer accessible. In order to adjust the compression level for example some code outside the actual handler would have to mess with the service configuration which is a significant logic break.

In case of compression this can be addressed by adjusting compression level in early_request_filter. When the handler wants to add its own module however (helps remove some work-arounds I’ve added before), this option is rather suboptimal.

So I’ve added an init_downstream_module phase where HttpProxy can adjust modules to its liking.

palant commented 2 weeks ago

When the handler wants to add its own module however (helps remove some work-arounds I’ve added before), this option is rather suboptimal.

Actually, I can see now that the module list is no longer mutable during early_request_filter, so adding modules isn’t even possible there. Hooking into the server initialization is really the only way.

eaufavor commented 1 week ago

You can access and mutate the modules here. Be this PR also provides a nicer API.

let mut proxy = http_proxy_service(...);
proxy.app_logic_mut().unwrap().downstream_modules
palant commented 1 week ago

You can access and mutate the modules here.

I know. As I said, doing this via some code outside the handler is possible but a significant logic break.

drcaramelsyrup commented 1 day ago

We've brought this into main as dda7bec58cb176228b8194e97c8c9e52bf36b878. Thanks!