Set the request body to a new ReadCloser

This commit is contained in:
Carter 2016-08-10 10:36:16 -04:00
parent 59b1e8b0bc
commit d06c15cae6

View File

@ -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 ""