Hello,
Imagine that I would like to use caddy go mod, programmatically, to do the following:
Every time a request comes, the request body should be evaluated (by a custom function or a pattern), and if matched, then forward/proxy the request to host X or host Y (with a given policy, which caddy already supports).
So, I imagine:
- load a configuration specifying patterns in the request body and to where it should be proxied through (proto://host:port)
- start caddy on port X
- every time a request arrives, evaluate the request body based on such configuration (e.g., “if the body contains X then forward the request to host X”)
I believe that caddy would allow me to do something like this:
- Specify a “middleware function” (out of caddy, but following some kind of interface) that gets in between the moment the request arrives and is forwarded to other steps in the pipeline (load balancer, etc).
- The only problem is that the outcome of such “middleware function” can also impact to where the request should be proxied to (I mean, this function could provide an array of hosts, for example).
I don’t know if I was pretty clear on the description because I could not look into v2 code yet (I just have v1 experience)… but, could you shed some light on where I could start looking into?
Cheers,
Guil.