]> Cypherpunks repositories - gostls13.git/commit
net/http: reuse client connections earlier when Content-Length is set
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 29 Jan 2014 10:23:45 +0000 (11:23 +0100)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 29 Jan 2014 10:23:45 +0000 (11:23 +0100)
commit01e3b4fc6aa13e126f61782ad42aa51ba490b302
tree3597866ffa2c5ba1832be6b4d4d294c3440ba1c4
parent45893ebdb8c7644cb96e7da0d7457bcd55bfd54d
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
src/pkg/net/http/transfer.go
src/pkg/net/http/transport_test.go