caddy
caddy copied to clipboard
feat: add generic response interceptors
In proxy mode, Caddy allows intercepting and modifying responses coming from upstream servers.
This is especially useful for implementing X-Sendfile/X-Accel-Redirect-like features.
However, the current implementation of this feature is only available in proxy mode and doesn't allow to intercept and modify responses created by modules.
This makes it impossible to use features like X-Sendfile with FrankenPHP, https://github.com/mliezun/caddy-snake, and other similar potential modules (LUA module, etc).
This patch implements a generic implementation of response interceptors that behaves similarly to the reverse_proxy handle_response subdirective.
It currently does not support the copy_response and copy_response_headers subdirective, but it should be easy to add support for these features in future Pull Requests.
It should also be possible, in the future, to replace the current reverse_proxy specific implementation with this new more generic one, but it is out of scope for this PR.
Closes https://github.com/dunglas/frankenphp/issues/365. Closes https://github.com/dunglas/frankenphp/pull/396.
Nice feature! Thanks @dunglas ! I posted asking for help configuring similar capability in this post on caddy forum few days ago.
Looking good here. @francislavoie any thoughts on the Caddyfile implementation?
@dunglas I'll probably tag 2.8 beta 1 this week; it'd be nice to get this in 2.8 beta 1, but if not, maybe we can get it in beta 2 or the RC.
@dunglas Before we merge this, can we mark the exported types/methods as "EXPERIMENTAL: Subject to change or removal" (or something like that)? It sounds like there are still decisions to be made to finalize APIs to accommodate expanded functionality later, and by marking it as experimental we can at least merge it in sooner and then change it, as opposed to making painful changes later on.
Sounds good to me to mark the public API as experimental. Should I update the code?
Yeah, if you have a chance to do that could you push a commit? I'm wrapping up a few things here.
@mholt done (the public type was already marked as experimental).