improve ghttp.Request for making the request body reusable for multiple times

This commit is contained in:
John
2020-02-06 11:22:36 +08:00
parent 95411aff77
commit 374ee4c0ea

View File

@ -14,7 +14,7 @@ import (
// bodyReadCloser implements the io.ReadCloser interface
// which is used for reading request body content multiple times.
type BodyReadCloser struct {
*bytes.Buffer
*bytes.Reader
}
// RefillBody refills the request body object after read all of its content.
@ -24,7 +24,7 @@ func (r *Request) RefillBody() {
r.bodyContent, _ = ioutil.ReadAll(r.Body)
}
r.Body = &BodyReadCloser{
bytes.NewBuffer(r.bodyContent),
bytes.NewReader(r.bodyContent),
}
}