diff options
author | Frédéric Guillot <fred@miniflux.net> | 2018-04-29 23:11:10 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2018-04-29 23:11:10 -0700 |
commit | 2f4cd59ad990ac1c43a2262279e3b1bd91cd18c7 (patch) | |
tree | 422aab0f8057e013d9bd4c5995f4aa8fe519bee7 /http | |
parent | 5cacae6cf2e1f2f59cf294139fd0c626a3b256fc (diff) |
Make sure to close request body in HTTP client
Diffstat (limited to 'http')
-rw-r--r-- | http/client/client.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/http/client/client.go b/http/client/client.go index 7663064..cba55c4 100644 --- a/http/client/client.go +++ b/http/client/client.go @@ -11,6 +11,7 @@ import ( "encoding/json" "fmt" "io" + "io/ioutil" "net" "net/http" "net/url" @@ -134,13 +135,19 @@ 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) } + buf, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, fmt.Errorf("client: error while reading body %v", err) + } + response := &Response{ - Body: resp.Body, + Body: bytes.NewReader(buf), StatusCode: resp.StatusCode, EffectiveURL: resp.Request.URL.String(), LastModified: resp.Header.Get("Last-Modified"), |