net/http: document response body close error handling #58406
Labels
Documentation
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Documentation of the
net/http
package suggests in two examples https://pkg.go.dev/net/http#pkg-overview and https://pkg.go.dev/net/http#example-Get to usedefer
to close response body and thus ignore returned error:securego
linter was recently changed to catch all unhandled errors ofio.ReadCloser.Close
and therefore it started to catch the very commondefer resp.Body.Close()
pattern, see discussion securego/gosec#925.It would be great to update package documentation examples with a proper error handling of
resp.Body.Close()
(or confirm thatdefer resp.Body.Close()
is a safe and recommended pattern).The text was updated successfully, but these errors were encountered: