Support httplib mock

This commit is contained in:
Ming Deng
2020-12-25 22:11:40 +08:00
parent bdd675e432
commit ef258a0988
8 changed files with 483 additions and 3 deletions

View File

@@ -338,10 +338,16 @@ func (b *BeegoHTTPRequest) Body(data interface{}) *BeegoHTTPRequest {
case string:
bf := bytes.NewBufferString(t)
b.req.Body = ioutil.NopCloser(bf)
b.req.GetBody = func() (io.ReadCloser, error) {
return ioutil.NopCloser(bf), nil
}
b.req.ContentLength = int64(len(t))
case []byte:
bf := bytes.NewBuffer(t)
b.req.Body = ioutil.NopCloser(bf)
b.req.GetBody = func() (io.ReadCloser, error) {
return ioutil.NopCloser(bf), nil
}
b.req.ContentLength = int64(len(t))
}
return b