Skip to content
Snippets Groups Projects
Commit 2f4cd59a authored by Frédéric Guillot's avatar Frédéric Guillot
Browse files

Make sure to close request body in HTTP client

parent 5cacae6c
No related branches found
No related tags found
No related merge requests found
......@@ -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"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment