change ReadAll to TeeReader
This commit is contained in:
parent
d907a55566
commit
85d0a71d13
9
main.go
9
main.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -167,9 +168,9 @@ func NewRecorderHandler(srv *CaptureService, next http.HandlerFunc) http.Handler
|
||||||
return func(rw http.ResponseWriter, r *http.Request) {
|
return func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Save req body for later.
|
// Save req body for later.
|
||||||
reqBody, _ := ioutil.ReadAll(r.Body)
|
|
||||||
r.Body.Close()
|
reqBody := &bytes.Buffer{}
|
||||||
r.Body = ioutil.NopCloser(bytes.NewReader(reqBody))
|
r.Body = ioutil.NopCloser(io.TeeReader(r.Body, reqBody))
|
||||||
|
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
|
|
||||||
|
@ -199,7 +200,7 @@ func NewRecorderHandler(srv *CaptureService, next http.HandlerFunc) http.Handler
|
||||||
Url: r.URL.String(),
|
Url: r.URL.String(),
|
||||||
Path: r.URL.Path,
|
Path: r.URL.Path,
|
||||||
Header: r.Header,
|
Header: r.Header,
|
||||||
Body: reqBody,
|
Body: reqBody.Bytes(),
|
||||||
}
|
}
|
||||||
res := Res{
|
res := Res{
|
||||||
Proto: rec.Result().Proto,
|
Proto: rec.Result().Proto,
|
||||||
|
|
Loading…
Reference in a new issue