mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
improve ghttp.Request for making the request body reusable for multiple times
This commit is contained in:
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user