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
net/http.Request.Body does not mention it will *not* get closed on errors:
// For client requests, a nil body means the request has no
// body, such as a GET request. The HTTP Client's Transport
// is responsible for calling the Close method.
net/http.RoundTripper does not mention Body will *not* get closed on errors:
// RoundTrip should not modify the request, except for
// consuming and closing the Body.
net/http.*Client.Do does not mention the behavior of Request.Body
Only net/http.*Client.Post hints the body is closed only when err == nil:
If the provided body is also an io.Closer, it is closed after the body is successfully written to the server.
Therefore, only a consumer of the Post API will get a hint that the request body is only
closed on successful requests.
It would be nice if other methods of sending requests clarified the behavior.
Reasoning: if you're using io.Pipe() to transform your request body, it's very easy to
deadlock your process if you don't properly close the io.PipeReader.
Unless you notice the *Client.Post docs, it takes a *lot* of digging through go's source
code to find precisely where request bodies are closed.
The text was updated successfully, but these errors were encountered:
I tried documenting this but as I did so, it was both gross and I was questioning why we
don't just always close it.
If we failed to write the whole body to the server, the Request.Body is left at a random
position anyway, and is therefore almost certainly useless.
I'd rather just always close it. It prevents leaks and is consistent.
Objections?
by michael.schurter:
The text was updated successfully, but these errors were encountered: