mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
reverseproxy: Replace health header placeholders (#5861)
This commit is contained in:
parent
33d8d2c6b5
commit
05dbe1c171
3 changed files with 21 additions and 5 deletions
|
@ -6,6 +6,9 @@ reverse_proxy 127.0.0.1:65535 {
|
||||||
X-Header-Key 95ca39e3cbe7
|
X-Header-Key 95ca39e3cbe7
|
||||||
X-Header-Keys VbG4NZwWnipo 335Q9/MhqcNU3s2TO
|
X-Header-Keys VbG4NZwWnipo 335Q9/MhqcNU3s2TO
|
||||||
X-Empty-Value
|
X-Empty-Value
|
||||||
|
Same-Key 1
|
||||||
|
Same-Key 2
|
||||||
|
X-System-Hostname {system.hostname}
|
||||||
}
|
}
|
||||||
health_uri /health
|
health_uri /health
|
||||||
}
|
}
|
||||||
|
@ -29,6 +32,10 @@ reverse_proxy 127.0.0.1:65535 {
|
||||||
"Host": [
|
"Host": [
|
||||||
"example.com"
|
"example.com"
|
||||||
],
|
],
|
||||||
|
"Same-Key": [
|
||||||
|
"1",
|
||||||
|
"2"
|
||||||
|
],
|
||||||
"X-Empty-Value": [
|
"X-Empty-Value": [
|
||||||
""
|
""
|
||||||
],
|
],
|
||||||
|
@ -38,6 +45,9 @@ reverse_proxy 127.0.0.1:65535 {
|
||||||
"X-Header-Keys": [
|
"X-Header-Keys": [
|
||||||
"VbG4NZwWnipo",
|
"VbG4NZwWnipo",
|
||||||
"335Q9/MhqcNU3s2TO"
|
"335Q9/MhqcNU3s2TO"
|
||||||
|
],
|
||||||
|
"X-System-Hostname": [
|
||||||
|
"{system.hostname}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"uri": "/health"
|
"uri": "/health"
|
||||||
|
|
|
@ -372,7 +372,7 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
if len(values) == 0 {
|
if len(values) == 0 {
|
||||||
values = append(values, "")
|
values = append(values, "")
|
||||||
}
|
}
|
||||||
healthHeaders[key] = values
|
healthHeaders[key] = append(healthHeaders[key], values...)
|
||||||
}
|
}
|
||||||
if h.HealthChecks == nil {
|
if h.HealthChecks == nil {
|
||||||
h.HealthChecks = new(HealthChecks)
|
h.HealthChecks = new(HealthChecks)
|
||||||
|
|
|
@ -358,11 +358,17 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, upstre
|
||||||
}
|
}
|
||||||
ctx = context.WithValue(ctx, caddyhttp.OriginalRequestCtxKey, *req)
|
ctx = context.WithValue(ctx, caddyhttp.OriginalRequestCtxKey, *req)
|
||||||
req = req.WithContext(ctx)
|
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" {
|
if key == "Host" {
|
||||||
req.Host = h.HealthChecks.Active.Headers.Get(key)
|
req.Host = repl.ReplaceAll(h.HealthChecks.Active.Headers.Get(key), "")
|
||||||
} else {
|
continue
|
||||||
req.Header[key] = hdrs
|
}
|
||||||
|
for _, val := range vals {
|
||||||
|
req.Header.Add(key, repl.ReplaceKnown(val, ""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue