Make sure to drain body upon an error (#7197)

Also cleanup redundant code and use it at a common place
This commit is contained in:
Harshavardhana
2019-02-06 12:07:03 -08:00
committed by kannappanr
parent 2d168b532b
commit 817269475f
9 changed files with 83 additions and 83 deletions

View File

@@ -59,9 +59,9 @@ func (c *Client) Call(method string, values url.Values, body io.Reader, length i
}
if resp.StatusCode != http.StatusOK {
defer xhttp.DrainBody(resp.Body)
// Limit the ReadAll(), just in case, because of a bug, the server responds with large data.
r := io.LimitReader(resp.Body, 1024)
b, err := ioutil.ReadAll(r)
b, err := ioutil.ReadAll(io.LimitReader(resp.Body, 4096))
if err != nil {
return nil, err
}