mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
33257de2e8
* Implement adding Host header to health check * Fix type problems * Fix duplicate function, Replace args * Add debugging * Add debugging * Add debugging * Add debugging * Attempt to set req.Host instead of the header * Clean up debugging * Fix missing newline * Fix spelling * Add test, refactoring * Fix with gofmt * Add error check on NewRequest
31 lines
680 B
Go
31 lines
680 B
Go
package proxy
|
|
|
|
import (
|
|
"github.com/mholt/caddy"
|
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
|
)
|
|
|
|
func init() {
|
|
caddy.RegisterPlugin("proxy", caddy.Plugin{
|
|
ServerType: "http",
|
|
Action: setup,
|
|
})
|
|
}
|
|
|
|
// setup configures a new Proxy middleware instance.
|
|
func setup(c *caddy.Controller) error {
|
|
upstreams, err := NewStaticUpstreams(c.Dispenser, httpserver.GetConfig(c).Host())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
|
|
return Proxy{Next: next, Upstreams: upstreams}
|
|
})
|
|
|
|
// Register shutdown handlers.
|
|
for _, upstream := range upstreams {
|
|
c.OnShutdown(upstream.Stop)
|
|
}
|
|
|
|
return nil
|
|
}
|