Commit d986daec authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: update some comments

And move some code to make control flow more obvious.
No functional change.

Change-Id: Iefaa96f664070ab2accade1857e1946e56df6902
Reviewed-on: https://go-review.googlesource.com/34285
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 48a5d993
...@@ -274,6 +274,11 @@ func send(ireq *Request, rt RoundTripper, deadline time.Time) (*Response, error) ...@@ -274,6 +274,11 @@ func send(ireq *Request, rt RoundTripper, deadline time.Time) (*Response, error)
// setRequestCancel sets the Cancel field of req, if deadline is // setRequestCancel sets the Cancel field of req, if deadline is
// non-zero. The RoundTripper's type is used to determine whether the legacy // non-zero. The RoundTripper's type is used to determine whether the legacy
// CancelRequest behavior should be used. // CancelRequest behavior should be used.
//
// As background, there are three ways to cancel a request:
// First was Transport.CancelRequest. (deprecated)
// Second was Request.Cancel (this mechanism).
// Third was Request.Context.
func setRequestCancel(req *Request, rt RoundTripper, deadline time.Time) (stopTimer func(), didTimeout func() bool) { func setRequestCancel(req *Request, rt RoundTripper, deadline time.Time) (stopTimer func(), didTimeout func() bool) {
if deadline.IsZero() { if deadline.IsZero() {
return nop, alwaysFalse return nop, alwaysFalse
...@@ -285,7 +290,7 @@ func setRequestCancel(req *Request, rt RoundTripper, deadline time.Time) (stopTi ...@@ -285,7 +290,7 @@ func setRequestCancel(req *Request, rt RoundTripper, deadline time.Time) (stopTi
req.Cancel = cancel req.Cancel = cancel
doCancel := func() { doCancel := func() {
// The new way: // The newer way (the second way in the func comment):
close(cancel) close(cancel)
// The legacy compatibility way, used only // The legacy compatibility way, used only
......
...@@ -923,6 +923,9 @@ func (t *Transport) getConn(treq *transportRequest, cm connectMethod) (*persistC ...@@ -923,6 +923,9 @@ func (t *Transport) getConn(treq *transportRequest, cm connectMethod) (*persistC
// value. // value.
select { select {
case <-req.Cancel: case <-req.Cancel:
// It was an error due to cancelation, so prioritize that
// error value. (Issue 16049)
return nil, errRequestCanceledConn
case <-req.Context().Done(): case <-req.Context().Done():
return nil, req.Context().Err() return nil, req.Context().Err()
case err := <-cancelc: case err := <-cancelc:
...@@ -935,9 +938,6 @@ func (t *Transport) getConn(treq *transportRequest, cm connectMethod) (*persistC ...@@ -935,9 +938,6 @@ func (t *Transport) getConn(treq *transportRequest, cm connectMethod) (*persistC
// return the original error message: // return the original error message:
return nil, v.err return nil, v.err
} }
// It was an error due to cancelation, so prioritize that
// error value. (Issue 16049)
return nil, errRequestCanceledConn
case pc := <-idleConnCh: case pc := <-idleConnCh:
// Another request finished first and its net.Conn // Another request finished first and its net.Conn
// became available before our dial. Or somebody // became available before our dial. Or somebody
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment