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: Restore request's original host and header (fix #3509)
We already restore them within the retry loop, but after successful proxy we didn't reset them, so as handlers bubble back up, they would see the values used for proxying. Thanks to @ziddey for identifying the cause.
Matthew Holt committed
Jul 17, 2020 at 17:54 UTC
246a31aacd7159acc009ff6d6497596a96533f73
1 file changed
+10
-3
modules/caddyhttp/reverseproxy/reverseproxy.go
+10
-3
@@ -329,10 +329,17 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht
329
fmt.Errorf("preparing request for upstream round-trip: %v", err))
330
}
331
332
- // we will need the original headers and Host
333
- // value if header operations are configured
334
- reqHeader := r.Header
332
+ // we will need the original headers and Host value if
333
+ // header operations are configured; and we should
334
+ // restore them after we're done if they are changed
335
+ // (for example, changing the outbound Host header
336
+ // should not permanently change r.Host; issue #3509)
337
reqHost := r.Host
338
+ reqHeader := r.Header
339
+ defer func() {
340
+ r.Host = reqHost
341
+ r.Header = reqHeader
342
+ }()
343
344
start := time.Now()
345