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

Defer closing body before checking HTTP status code #2870

Merged
merged 1 commit into from Aug 15, 2023

Conversation

nikpivkin
Copy link
Contributor

This is a quote from the documentation of the net/http package:

When err is nil, resp always contains a non-nil resp.Body. Caller should close resp.Body when done reading from it.

In the current implementation, if the error code is 404, the response body will not close.

@codecov
Copy link

codecov bot commented Aug 14, 2023

Codecov Report

Merging #2870 (0d2e4db) into master (899235e) will increase coverage by 0.00%.
Report is 2 commits behind head on master.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #2870   +/-   ##
=======================================
  Coverage   98.06%   98.07%           
=======================================
  Files         138      139    +1     
  Lines       12327    12342   +15     
=======================================
+ Hits        12089    12104   +15     
  Misses        162      162           
  Partials       76       76           

see 2 files with indirect coverage changes

@gmlewis gmlewis changed the title fix: defer closing body after checking error Defer closing body before checking HTTP status code Aug 14, 2023
Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @nikpivkin !
LGTM.

Awaiting second LGTM+Approval from any other contributor to this repo before merging.

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Aug 14, 2023
Copy link
Contributor

@vandanrohatgi vandanrohatgi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. LGTM!

@gmlewis gmlewis removed the NeedsReview PR is awaiting a review before merging. label Aug 15, 2023
@gmlewis
Copy link
Collaborator

gmlewis commented Aug 15, 2023

Thank you, @vandanrohatgi ! ❤️
Merging.

@gmlewis gmlewis merged commit bb00f57 into google:master Aug 15, 2023
9 checks passed
@nikpivkin nikpivkin deleted the fix/close-resp-body branch August 16, 2023 04:04
gmlewis pushed a commit to gmlewis/go-github that referenced this pull request Sep 19, 2023
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 this pull request may close these issues.

None yet

3 participants