From 385adf5d878939c381c7f73c771771d34523a1a7 Mon Sep 17 00:00:00 2001 From: Matt Holt Date: Tue, 13 Oct 2020 10:52:39 -0600 Subject: caddyhttp: Restore original request params before error handlers (#3781) * caddyhttp: Restore original request params before error handlers Fixes #3717 * Add comment --- modules/caddyhttp/server.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go index 4f198e5..aaec711 100644 --- a/modules/caddyhttp/server.go +++ b/modules/caddyhttp/server.go @@ -209,6 +209,14 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + // restore original request before invoking error handler chain (issue #3717) + // TODO: this does not restore original headers, if modified (for efficiency) + origReq := r.Context().Value(OriginalRequestCtxKey).(http.Request) + r.Method = origReq.Method + r.RemoteAddr = origReq.RemoteAddr + r.RequestURI = origReq.RequestURI + cloneURL(origReq.URL, r.URL) + // prepare the error log logger := errLog if s.Logs != nil { -- cgit v1.2.3