Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drain Response.Body #3

Closed
DmitriyMV opened this issue Jun 23, 2016 · 1 comment
Closed

Drain Response.Body #3

DmitriyMV opened this issue Jun 23, 2016 · 1 comment

Comments

@DmitriyMV
Copy link
Contributor

DmitriyMV commented Jun 23, 2016

Since you're using json.Decoder, I think it would be wise to drain response body for connection reuse. See relevant issue:
google/go-github#317
Discussion:
https://stackoverflow.com/questions/17948827/reusing-http-connections-in-golang
https://groups.google.com/forum/#!search/golang%2420json%2420decode%2420%2420io.Copy/golang-nuts/4Rr8BYVKrAI/ZrJJFTNleekJ
Solution to this would be something like this

defer func() {
    io.CopyN(ioutil.Discard, resp.Body, 512)
    resp.Body.Close()
}()

in here

defer resp.Body.Close()

If you want I can make a pull request.

Cheers.

@yanatan16
Copy link
Owner

Good idea. I haven't used this project in a while. Would you write a PR please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants