Hi,
I’m looking to use Caddy as a frontend for a set of fastcgi servers, with the condition that the selected backend depends on request data such as the host and headers, and I cannot determine ahead of time what those will be.
Ideally, to make the Caddyfile clearer, I’d like to write a plugin that exposes a placeholder, such as:
myplugin {
some stuff
}
fastcgi / {mypluginbackend} php
But from looking at the code, it seems no replacement takes place when extracting the server address.
Another option, which I’m not sure would work, is to write a pĺugin that actually calls the fastcgi middleware from it, creating the Handler and Rules manually and then calling ServeHTTP
, something like:
func (h MyPluginHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
fgciHandler := createFastcgiHandler(r)
fcgiHandler.ServeHTTP(w, r)
}
About these two options:
- For option one, would a
Replacer
be all that’s needed to get the placeholder expanded for the address? Not sure if this would make a good PR because this might incur some penalty for all fastcgi requests, even those not using replacements. Could also add a new option similar toupstream
that would run replacements. There’s already an indirection when getting the server address so a new type ofbalancer
wouldn’t cause issues for existing fastcgi blocks, I believe. Though it increases the module’s complexity - For option two, is that possible? Are there drawbacks/limitations to this approach? With this one I wouldn’t have to modify Caddy itself, but since I’m still new to Caddy I’m not sure if this is a supported pattern
Thanks,
Felipe