Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
reverseproxy: Set X-Forwarded-Proto (closes #3275) (#3276)
Matt Holt committed
Apr 17, 2020 at 09:53 UTC
76bbb473a57f60a9c7f62afc61a93d10a8720ab5
1 file changed
+15
modules/caddyhttp/reverseproxy/reverseproxy.go
+15
@@ -74,11 +74,19 @@ type Handler struct {
74
// Upstreams is the list of backends to proxy to.
75
Upstreams UpstreamPool `json:"upstreams,omitempty"`
76
77
+ // Adjusts how often to flush the response buffer. A
78
+ // negative value disables response buffering.
79
// TODO: figure out good defaults and write docs for this
80
// (see https://github.com/caddyserver/caddy/issues/1460)
81
FlushInterval caddy.Duration `json:"flush_interval,omitempty"`
82
83
// Headers manipulates headers between Caddy and the backend.
84
+ // By default, all headers are passed-thru without changes,
85
+ // with the exceptions of special hop-by-hop headers.
86
+ //
87
+ // X-Forwarded-For and X-Forwarded-Proto are also set
88
+ // implicitly, but this may change in the future if the official
89
+ // standardized Forwarded header field gains more adoption.
90
Headers *headers.Handler `json:"headers,omitempty"`
91
92
// If true, the entire request body will be read and buffered
@@ -423,6 +431,13 @@ func (h Handler) prepareRequest(req *http.Request) error {
431
req.Header.Set("X-Forwarded-For", clientIP)
432
}
433
434
+ // set X-Forwarded-Proto; many backend apps expect this too
435
+ proto := "https"
436
+ if req.TLS == nil {
437
+ proto = "http"
438
+ }
439
+ req.Header.Set("X-Forwarded-Proto", proto)
440
+
441
return nil
442
}
443