Skip to content

Instantly share code, notes, and snippets.

@cep21
Last active July 7, 2016 23:37
Show Gist options
  • Save cep21/220b3253891b177401eaa2de9603be06 to your computer and use it in GitHub Desktop.
Save cep21/220b3253891b177401eaa2de9603be06 to your computer and use it in GitHub Desktop.
Example draining http response
func (c *Client) doRequest(req *http.Request) {
resp, err := c.client.Do(req)
if err != nil {
return err
}
defer func() {
maxCopySize := 2 << 10
io.CopyN(ioutil.Discard, resp.Body, maxCopySize)
resp.Close()
}()
// ....
}
@djui
Copy link

djui commented Jul 7, 2016

Small correction: s/resp.Close()/resp.Body.Close()/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment