-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: try HEAD request before GET #16
Conversation
License: MIT Signed-off-by: Henrique Dias <hacdias@gmail.com>
@willnorris I see the CI fails because
|
I don't want break it from working in go1.15 if we don't have to, even if it's not technically in the support window of two latest releases. I'm currently deep into the source code for net/http trying to figure out if we need to close the body ourselves :) The response body certainly it needs to be read to completion... the docs are pretty clear on that. What I haven't yet found is whether the standard resp.Body.Close() call does that for us. This comment suggests that it does, but I'm not 100% sure that the linked |
Okay, so I don't think discarding the body like this is harmful in any way, since it's basically what |
Okay, I removed it then. I found contradicting information from many sources so I'm also quite curious about what's actually happening behind the scenes. |
well, somewhat hilariously, I just found google/go-github#317 and remembered that I dealt with this exact problem 5 years ago there :) That's probably the best source of info on what's going on, and includes some background from bradfitz. And interestingly, we did decide to always drain in that case, though it was later removed as unnecessary in google/go-github#843. because it had gotten fixed in the stdlib. So yeah, I think leaving this out is the right call until there is specific indication that it's necessary. Thanks for this patch! |
I added the HEAD request first.
I also made sure the body is discarded before closing the connection so the http.Client can reuse the TCP connections. I heard this is needed, but I found contradicting information...
Closes #5
License: MIT
Signed-off-by: Henrique Dias hacdias@gmail.com