diff options
author | Francis Lavoie <lavofr@gmail.com> | 2023-10-11 11:50:28 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-11 09:50:28 -0600 |
commit | 05dbe1c171846b0b683dedbe2c4c20683e867ba0 (patch) | |
tree | 7c4e129a7635af64dd887f7ad2e9262794c2bece /modules/caddyhttp | |
parent | 33d8d2c6b5e070d108d69853b8d56fb2f89a1f31 (diff) |
reverseproxy: Replace health header placeholders (#5861)
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r-- | modules/caddyhttp/reverseproxy/caddyfile.go | 2 | ||||
-rw-r--r-- | modules/caddyhttp/reverseproxy/healthchecks.go | 14 |
2 files changed, 11 insertions, 5 deletions
diff --git a/modules/caddyhttp/reverseproxy/caddyfile.go b/modules/caddyhttp/reverseproxy/caddyfile.go index 533a82e..95293f0 100644 --- a/modules/caddyhttp/reverseproxy/caddyfile.go +++ b/modules/caddyhttp/reverseproxy/caddyfile.go @@ -372,7 +372,7 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { if len(values) == 0 { values = append(values, "") } - healthHeaders[key] = values + healthHeaders[key] = append(healthHeaders[key], values...) } if h.HealthChecks == nil { h.HealthChecks = new(HealthChecks) diff --git a/modules/caddyhttp/reverseproxy/healthchecks.go b/modules/caddyhttp/reverseproxy/healthchecks.go index 1b4f2d0..ad21ccb 100644 --- a/modules/caddyhttp/reverseproxy/healthchecks.go +++ b/modules/caddyhttp/reverseproxy/healthchecks.go @@ -358,11 +358,17 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, upstre } ctx = context.WithValue(ctx, caddyhttp.OriginalRequestCtxKey, *req) req = req.WithContext(ctx) - for key, hdrs := range h.HealthChecks.Active.Headers { + + // set headers, using a replacer with only globals (env vars, system info, etc.) + repl := caddy.NewReplacer() + for key, vals := range h.HealthChecks.Active.Headers { + key = repl.ReplaceAll(key, "") if key == "Host" { - req.Host = h.HealthChecks.Active.Headers.Get(key) - } else { - req.Header[key] = hdrs + req.Host = repl.ReplaceAll(h.HealthChecks.Active.Headers.Get(key), "") + continue + } + for _, val := range vals { + req.Header.Add(key, repl.ReplaceKnown(val, "")) } } |