Last active
July 7, 2016 23:37
-
-
Save cep21/220b3253891b177401eaa2de9603be06 to your computer and use it in GitHub Desktop.
Example draining http response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
}() | |
// .... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Small correction: s/
resp.Close()
/resp.Body.Close()
/.