caddyhttp: Restore original request params before error handlers (#3781)

* caddyhttp: Restore original request params before error handlers

Fixes #3717

* Add comment
This commit is contained in:
Matt Holt 2020-10-13 10:52:39 -06:00 committed by GitHub
parent c7efb0307d
commit 385adf5d87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -209,6 +209,14 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return 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 // prepare the error log
logger := errLog logger := errLog
if s.Logs != nil { if s.Logs != nil {