summaryrefslogtreecommitdiff
path: root/src/pkg/net/http/transport.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2012-05-21 10:39:31 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2012-05-21 10:39:31 -0700
commit1e79b61b38bfb5de937fa3237ad7d18ba19c3a49 (patch)
tree058665e9862a182981966b7a20ff0e1c31d4fc3e /src/pkg/net/http/transport.go
parent9c09b567d5632c690a86f10abf501c2b9918f461 (diff)
downloadgo-1e79b61b38bfb5de937fa3237ad7d18ba19c3a49.tar.gz
net/http: fix regression and mute known test failure for now
Two tests added in 820ffde8c are expected to fail until the fix for Issue 3540 goes back in (pending Windows net fixes), so make those tests just Logf for now, with a TODO to re-enable. Add a new client test. Rearrange the transport code to be more readable, and fix the bug from 820ffde8c where the persistConn was being closed before the body was fully ready. Fixes issue 3644 Updates issue 1967 (not yet fixed, but should be after Issue 3540) R=golang-dev, adg CC=golang-dev http://codereview.appspot.com/6211069
Diffstat (limited to 'src/pkg/net/http/transport.go')
-rw-r--r--src/pkg/net/http/transport.go48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/pkg/net/http/transport.go b/src/pkg/net/http/transport.go
index 5f3d3fbfb..fc06e207e 100644
--- a/src/pkg/net/http/transport.go
+++ b/src/pkg/net/http/transport.go
@@ -567,29 +567,29 @@ func (pc *persistConn) readLoop() {
hasBody := resp != nil && resp.ContentLength != 0
var waitForBodyRead chan bool
- if alive {
- if hasBody {
- lastbody = resp.Body
- waitForBodyRead = make(chan bool)
- resp.Body.(*bodyEOFSignal).fn = func() {
- if !pc.t.putIdleConn(pc) {
- alive = false
- }
- waitForBodyRead <- true
- }
- } else {
- // When there's no response body, we immediately
- // reuse the TCP connection (putIdleConn), but
- // we need to prevent ClientConn.Read from
- // closing the Response.Body on the next
- // loop, otherwise it might close the body
- // before the client code has had a chance to
- // read it (even though it'll just be 0, EOF).
- lastbody = nil
-
- if !pc.t.putIdleConn(pc) {
+ if hasBody {
+ lastbody = resp.Body
+ waitForBodyRead = make(chan bool)
+ resp.Body.(*bodyEOFSignal).fn = func() {
+ if alive && !pc.t.putIdleConn(pc) {
alive = false
}
+ waitForBodyRead <- true
+ }
+ }
+
+ if alive && !hasBody {
+ // When there's no response body, we immediately
+ // reuse the TCP connection (putIdleConn), but
+ // we need to prevent ClientConn.Read from
+ // closing the Response.Body on the next
+ // loop, otherwise it might close the body
+ // before the client code has had a chance to
+ // read it (even though it'll just be 0, EOF).
+ lastbody = nil
+
+ if !pc.t.putIdleConn(pc) {
+ alive = false
}
}
@@ -599,9 +599,9 @@ func (pc *persistConn) readLoop() {
// before we race and peek on the underlying bufio reader.
if waitForBodyRead != nil {
<-waitForBodyRead
- } else if !alive {
- // If waitForBodyRead is nil, and we're not alive, we
- // must close the connection before we leave the loop.
+ }
+
+ if !alive {
pc.close()
}
}