reverseproxy: Set X-Forwarded-Proto (closes #3275) (#3276)

This commit is contained in:
Matt Holt 2020-04-17 09:53:06 -06:00 committed by GitHub
parent 3c70950fa1
commit 76bbb473a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -74,11 +74,19 @@ type Handler struct {
// Upstreams is the list of backends to proxy to.
Upstreams UpstreamPool `json:"upstreams,omitempty"`
// Adjusts how often to flush the response buffer. A
// negative value disables response buffering.
// TODO: figure out good defaults and write docs for this
// (see https://github.com/caddyserver/caddy/issues/1460)
FlushInterval caddy.Duration `json:"flush_interval,omitempty"`
// Headers manipulates headers between Caddy and the backend.
// By default, all headers are passed-thru without changes,
// with the exceptions of special hop-by-hop headers.
//
// X-Forwarded-For and X-Forwarded-Proto are also set
// implicitly, but this may change in the future if the official
// standardized Forwarded header field gains more adoption.
Headers *headers.Handler `json:"headers,omitempty"`
// If true, the entire request body will be read and buffered
@ -423,6 +431,13 @@ func (h Handler) prepareRequest(req *http.Request) error {
req.Header.Set("X-Forwarded-For", clientIP)
}
// set X-Forwarded-Proto; many backend apps expect this too
proto := "https"
if req.TLS == nil {
proto = "http"
}
req.Header.Set("X-Forwarded-Proto", proto)
return nil
}