You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current version of bodyclose only run analysis on http.Response. It's quite common that people use the same behaviour on http.Request (on server side) which is not really necessary. According to the documentation for http.Request, the Body field has the following comment:
// For server requests, the Request Body is always non-nil
// but will return EOF immediately when no body is present.
// The Server will close the request body. The ServeHTTP
// Handler does not need to.
Body io.ReadCloser
If the returned error is nil, the Response will contain a non-nil Body which the user is expected to close. If the Body is not both read to EOF and closed, the Client's underlying RoundTripper (typically Transport) may not be able to re-use a persistent TCP connection to the server for a subsequent "keep-alive" request.
// The http Client and Transport guarantee that Body is always
// non-nil, even on responses without a body or responses with
// a zero-length body. It is the caller's responsibility to
// close Body. The default HTTP client's Transport may not
// reuse HTTP/1.x "keep-alive" TCP connections if the Body is
// not read to completion and closed.
Since that does not apply to the server side, this means that code like this is not needed:
The current version of
bodyclose
only run analysis onhttp.Response
. It's quite common that people use the same behaviour onhttp.Request
(on server side) which is not really necessary. According to the documentation for http.Request, theBody
field has the following comment:(Also confirmed by this SO post)
The reason to close the
http.Response
body can be found in the documentation for http.Client.Do:And documentation for http.Response
Body
field:Since that does not apply to the server side, this means that code like this is not needed:
It would be nice if the linter was telling you to remove the line closing the
http.Request
body. If you agree, are you open to pull requests?The text was updated successfully, but these errors were encountered: