-
Notifications
You must be signed in to change notification settings - Fork 107
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
Read, close and replace the http Reponse Body #300
Conversation
b0dc736
to
eb5be7f
Compare
Looks good, needs a unit test, including to what happens with a double close by the caller. |
aaea13b
to
eb5be7f
Compare
I am not 100% sure what kind of test you expect. Before this MR and after this MR the user can call Close() as often as they want. As the NopCloser just returns nil when calling Close it is obsolete to call it and to test it? |
I think of tests as expectations to prevent regressions. Imagine the implementation changes, what behavior do you expect?
|
Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
eb5be7f
to
f889dc7
Compare
@dblock I added a test. It will fail if the resp.Body is not a NopCloser. Without my added change it would fail with following error:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good.
Description
With this change the http reponse body gets automatically closed by us so the user don't have to do it and it prevents unclosed connections if the user forgot to close it. This wont brake any existing implementations as you can still call
.Close()
on the Body.Issues Resolved
https://pkg.go.dev/net/http#Client.Do
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.