Close HTTP response body even for failed requests
This commit is contained in:
parent
be95e87e0e
commit
7914261437
1 changed files with 4 additions and 1 deletions
|
@ -112,6 +112,10 @@ func (c *Client) executeRequest(request *http.Request) (*Response, error) {
|
|||
|
||||
client := c.buildClient()
|
||||
resp, err := client.Do(request)
|
||||
if resp != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if uerr, ok := err.(*url.Error); ok {
|
||||
switch uerr.Err.(type) {
|
||||
|
@ -135,7 +139,6 @@ func (c *Client) executeRequest(request *http.Request) (*Response, error) {
|
|||
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.ContentLength > maxBodySize {
|
||||
return nil, fmt.Errorf("client: response too large (%d bytes)", resp.ContentLength)
|
||||
|
|
Loading…
Reference in a new issue