net/http: reuse client connections earlier when Content-Length is set
Set EOF on the final Read of a body with a Content-Length, which will cause clients to recycle their connection immediately upon the final Read, rather than waiting for another Read or Close (neither of which might come). This happens often when client code is simply something like: err := json.NewDecoder(resp.Body).Decode(&dest) ... Then there's usually no subsequent Read. Even if the client calls Close (which they should): in Go 1.1, the body was slurped to EOF, but in Go 1.2, that was then treated as a Close-before-EOF and the underlying connection was closed. But that's assuming the user even calls Close. Many don't. Reading to EOF also causes a connection be reused. Now the EOF arrives earlier. This CL only addresses the Content-Length case. A future CL will address the chunked case. LGTM=adg R=adg CC=golang-codereviews https://golang.org/cl/49570044
Showing
Please
register
or
sign in
to comment