diff --git a/caddyhttp/httpserver/replacer.go b/caddyhttp/httpserver/replacer.go index ee4dc202..cf7dfccc 100644 --- a/caddyhttp/httpserver/replacer.go +++ b/caddyhttp/httpserver/replacer.go @@ -1,6 +1,7 @@ package httpserver import ( + "bytes" "io/ioutil" "log" "net" @@ -127,6 +128,9 @@ func NewReplacer(r *http.Request, rr *ResponseRecorder, emptyValue string) Repla } body, err := ioutil.ReadAll(r.Body) + // Create a new ReadCloser to keep the body from being drained. + r.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + if err != nil { log.Printf("[WARNING] Cannot read request body %v", err) return ""