reverse_proxy: Add 'transparent' Caddyfile subdirective (closes #2873)

This commit is contained in:
Matthew Holt 2020-02-27 10:20:13 -07:00
parent f6ae092507
commit 86b785e51c
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5

View file

@ -411,6 +411,21 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
} }
h.TransportRaw = caddyconfig.JSONModuleObject(rt, "protocol", name, nil) h.TransportRaw = caddyconfig.JSONModuleObject(rt, "protocol", name, nil)
case "transparent":
if d.NextArg() {
return d.ArgErr()
}
if h.Headers == nil {
h.Headers = new(headers.Handler)
}
if h.Headers.Request == nil {
h.Headers.Request = new(headers.HeaderOps)
}
// The X-Forwarded-For header is always appended to by default, directly in the reverse proxy code
headers.CaddyfileHeaderOp(h.Headers.Request, "Host", "{http.request.hostport}", "")
headers.CaddyfileHeaderOp(h.Headers.Request, "X-Real-Ip", "{http.request.remote}", "")
headers.CaddyfileHeaderOp(h.Headers.Request, "X-Forwarded-Proto", "{http.request.scheme}", "")
default: default:
return d.Errf("unrecognized subdirective %s", d.Val()) return d.Errf("unrecognized subdirective %s", d.Val())
} }