go - is resp.Body.Close() necessary if we don't read anything from the body? -


i have function makes request check status code. not read body. should still end function resp.body.close() ?

callers should close resp.body when done reading it. if resp.body not closed, client's underlying roundtripper (typically transport) may not able re-use persistent tcp connection server subsequent "keep-alive" request.

yes. when call http.get, function returns response http headers have been read. body of response has not been read yet. response.body wrapper around network connection server. when read it, downloads body of response.

.close() tells system you're done network connection. if have not read response body, default http transport closes connection. (the transport can re-use connection if body has been read, because if reused connection unread body next request made using connection receive previous request's response!)

so reading body more efficient close()ing if you're making more 1 request - tls connections relatively expensive create.

if don't need body of response, should use head instead of get. head doesn't require reading or closing response body.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -