1
0
Fork 0

Close HTTP response body even for failed requests

This commit is contained in:
Frédéric Guillot 2018-06-19 20:13:13 -07:00
parent be95e87e0e
commit 7914261437

View file

@ -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)