]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.15] net/http: fix detection of Roundtrippers that always error
authorMichael Fraenkel <michael.fraenkel@gmail.com>
Fri, 17 Jul 2020 03:30:12 +0000 (21:30 -0600)
committerDmitri Shuralyov <dmitshur@golang.org>
Mon, 29 Mar 2021 15:50:54 +0000 (15:50 +0000)
CL 220905 added code to identify alternate transports that always error
by using http2erringRoundTripper. This does not work when the transport
is from another package, e.g., http2.erringRoundTripper.
Expose a new method that allow detection of such a RoundTripper.
Switch to an interface that is both a RoundTripper and can return the
underlying error.

Fixes #45076.
Updates #40213.

Change-Id: I170739857ab9e99dffb5fa55c99b24b23c2f9c54
Reviewed-on: https://go-review.googlesource.com/c/go/+/243258
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/go/+/304210
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
src/net/http/omithttp2.go
src/net/http/transport.go

index 7e2f4925798f81a1bf37847f36eb992dce600e59..c8f5c28a59135d935c2a339c7c38a5684fc2950b 100644 (file)
@@ -32,10 +32,6 @@ type http2Transport struct {
 func (*http2Transport) RoundTrip(*Request) (*Response, error) { panic(noHTTP2) }
 func (*http2Transport) CloseIdleConnections()                 {}
 
-type http2erringRoundTripper struct{ err error }
-
-func (http2erringRoundTripper) RoundTrip(*Request) (*Response, error) { panic(noHTTP2) }
-
 type http2noDialH2RoundTripper struct{}
 
 func (http2noDialH2RoundTripper) RoundTrip(*Request) (*Response, error) { panic(noHTTP2) }
index 6e430b9885fcb9c20e0ec1cdf6bba20052d82d6c..88d15a59194916f6c4433072f3cb907187345b8a 100644 (file)
@@ -1531,6 +1531,10 @@ func (pconn *persistConn) addTLS(name string, trace *httptrace.ClientTrace) erro
        return nil
 }
 
+type erringRoundTripper interface {
+       RoundTripErr() error
+}
+
 func (t *Transport) dialConn(ctx context.Context, cm connectMethod) (pconn *persistConn, err error) {
        pconn = &persistConn{
                t:             t,
@@ -1697,9 +1701,9 @@ func (t *Transport) dialConn(ctx context.Context, cm connectMethod) (pconn *pers
        if s := pconn.tlsState; s != nil && s.NegotiatedProtocolIsMutual && s.NegotiatedProtocol != "" {
                if next, ok := t.TLSNextProto[s.NegotiatedProtocol]; ok {
                        alt := next(cm.targetAddr, pconn.conn.(*tls.Conn))
-                       if e, ok := alt.(http2erringRoundTripper); ok {
+                       if e, ok := alt.(erringRoundTripper); ok {
                                // pconn.conn was closed by next (http2configureTransport.upgradeFn).
-                               return nil, e.err
+                               return nil, e.RoundTripErr()
                        }
                        return &persistConn{t: t, cacheKey: pconn.cacheKey, alt: alt}, nil
                }