0

I just want to ask, on the http.Client.Do response, I am just interested on the response status code and the cookie, and I am not gonna read the response body.

If I will not read the body, do I i still required to call response.body.close()?

Thanks

zer09
  • 1,507
  • 2
  • 28
  • 48
  • Also related: [Do we need to close the response object if an error occurs while calling http.Get(url)?](https://stackoverflow.com/questions/32818472/do-we-need-to-close-the-response-object-if-an-error-occurs-while-calling-http-ge/32819910#32819910) – icza Mar 29 '18 at 02:28
  • Probably not a duplicate, as mentioned I am not going to read the body. Correct me if I am wrong. @icza – zer09 Mar 29 '18 at 02:35
  • 1
    It doesn't matter whether you read it or not, you have to close it. _"The client must close the response body when finished with it"_ Here "when finished with it" means "when you don't need it anymore". – icza Mar 29 '18 at 02:38
  • @icza btw is there any difference between the ```response.close``` and the ```response.body.close```? it is a little vague for me, on the docs. – zer09 Mar 29 '18 at 02:49
  • `http.Response` does not have a `Close()` method, only a `Close` field which: _"Close records whether the header directed that the connection be closed after reading Body"_. – icza Mar 29 '18 at 02:56

0 Answers0