mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
improve ghttp.Client
This commit is contained in:
@ -227,6 +227,10 @@ func (c *Client) DoRequest(method, url string, data ...interface{}) (resp *Clien
|
||||
req.Body = utils.NewReadCloser(reqBodyContent, false)
|
||||
for {
|
||||
if resp.Response, err = c.Do(req); err != nil {
|
||||
// The response might not be nil when err != nil.
|
||||
if resp.Response != nil {
|
||||
resp.Response.Body.Close()
|
||||
}
|
||||
if c.retryCount > 0 {
|
||||
c.retryCount--
|
||||
time.Sleep(c.retryInterval)
|
||||
|
||||
@ -63,6 +63,9 @@ func (r *ClientResponse) ReadAllString() string {
|
||||
|
||||
// Close closes the response when it will never be used.
|
||||
func (r *ClientResponse) Close() error {
|
||||
if r == nil || r.Response == nil || r.Response.Close {
|
||||
return nil
|
||||
}
|
||||
r.Response.Close = true
|
||||
return r.Response.Body.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user