Whereas engaged on REST APIs, we often make sure the response physique is closed. Nevertheless, a colleague steered that the request physique also needs to be closed. From what I’ve learn in varied blogs, it appears there’s no have to explicitly shut the request physique because the server routinely handles it.
My questions are:
- Is it needed to shut the request physique? If sure:
a. Who’s liable for closing the request physique — the consumer or the server?
b. Do we have to explicitly shut the request physique, or is it routinely closed by the consumer/server?
Thanks,
Madhusudan
Sure, you could shut it.
One thing like;
consumer := http.DefaultClient
resp, err := consumer.Do(req)
if err != nil {
return nil, err
}
defer resp.Physique.Shut()