diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/caddyhttp/reverseproxy/caddyfile.go | 23 | ||||
-rw-r--r-- | modules/caddyhttp/reverseproxy/healthchecks.go | 7 |
2 files changed, 29 insertions, 1 deletions
diff --git a/modules/caddyhttp/reverseproxy/caddyfile.go b/modules/caddyhttp/reverseproxy/caddyfile.go index 4a69287..57f425a 100644 --- a/modules/caddyhttp/reverseproxy/caddyfile.go +++ b/modules/caddyhttp/reverseproxy/caddyfile.go @@ -63,6 +63,9 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) // health_timeout <duration> // health_status <status> // health_body <regexp> +// health_headers { +// <field> [<values...>] +// } // // # passive health checking // max_fails <num> @@ -313,6 +316,26 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { } h.HealthChecks.Active.Port = portNum + case "health_headers": + healthHeaders := make(http.Header) + for d.Next() { + for d.NextBlock(0) { + key := d.Val() + values := d.RemainingArgs() + if len(values) == 0 { + values = append(values, "") + } + healthHeaders[key] = values + } + } + if h.HealthChecks == nil { + h.HealthChecks = new(HealthChecks) + } + if h.HealthChecks.Active == nil { + h.HealthChecks.Active = new(ActiveHealthChecks) + } + h.HealthChecks.Active.Headers = healthHeaders + case "health_interval": if !d.NextArg() { return d.ArgErr() diff --git a/modules/caddyhttp/reverseproxy/healthchecks.go b/modules/caddyhttp/reverseproxy/healthchecks.go index 285834b..42003b6 100644 --- a/modules/caddyhttp/reverseproxy/healthchecks.go +++ b/modules/caddyhttp/reverseproxy/healthchecks.go @@ -26,6 +26,7 @@ import ( "regexp" "runtime/debug" "strconv" + "strings" "time" "github.com/caddyserver/caddy/v2" @@ -241,7 +242,11 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, host H return fmt.Errorf("making request: %v", err) } for key, hdrs := range h.HealthChecks.Active.Headers { - req.Header[key] = hdrs + if strings.ToLower(key) == "host" { + req.Host = h.HealthChecks.Active.Headers.Get(key) + } else { + req.Header[key] = hdrs + } } // do the request, being careful to tame the response body |