> On Nov 25, 2019, at 9:54 AM, Liam <
networ...@gmail.com> wrote:
>
> - does the read-to-EOF stipulation also apply to Client.Get/Post() ?
Yes. Those methods are fairly simple wrappers around Do.
> - why does Response.Body.Close() before io.EOF not release unread buffers or otherwise prepare it for persistence?
The connection can’t be reused for another request before all the data from the first request is read. The server is sending those bytes over the wire, and they need to go somewhere before another response can be read. So there were two options for how to implement Close when the whole body hasn’t been read:
1. Copy the rest of the body to /dev/null (or equivalent), and reuse the connection like normal.
2. Close the connection, thus communicating to the server that we don’t need that data after all.
Option 1 would generally be preferable for short responses, and option 2 for long ones. For consistency, and because we don’t always know the response length in advance (e.g. if it is chunked), it always does option 2.
Andy