FAQ

On Sep 16, 2014, at 5:36 PM, Jesse McNelis wrote:
On Wed, Sep 17, 2014 at 8:00 AM, James Bardin wrote:
I feel like I've seen it mentioned somewhere that you don't need to close an
http.Response.Body if you didn't use the response.
But, I can't find that anywhere in the official docs.

The docs say (currently) "Caller should close resp.Body when done reading
from it", but there's no mention that resp.Body *must* be closed.

Am I mis-remembering something, or is
_, err := http.Get(url)

not supposed to leak connections?
Something has to be done with the data waiting to be sent to you on
the connection.
Calling .Close() on the Response.Body tells the http.Client to read
the data from the connection and discard it(or to close the connection
if the amount to read is too large)
I believe you have to actually read the entire body yourself -- with something like io.Copy + ioutil.Discard if
you don't care about it.
If you just call response.Body.Close() without reading till EOF, the conn is just closed and discarded (not reused).

http://golang.org/src/pkg/net/http/transport.go#L869

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 7 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 16, '14 at 10:00p
activeSep 17, '14 at 7:28a
posts7
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase