Skip to content

Commit be87281

Browse files
fraenkeldmitshur
authored andcommitted
[release-branch.go1.15] net/http: fix detection of Roundtrippers that always error
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 <[email protected]> Run-TryBot: Emmanuel Odeke <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/go/+/304210 Trust: Dmitri Shuralyov <[email protected]> Trust: Emmanuel Odeke <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]>
1 parent 69b9431 commit be87281

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/net/http/omithttp2.go

-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ type http2Transport struct {
3232
func (*http2Transport) RoundTrip(*Request) (*Response, error) { panic(noHTTP2) }
3333
func (*http2Transport) CloseIdleConnections() {}
3434

35-
type http2erringRoundTripper struct{ err error }
36-
37-
func (http2erringRoundTripper) RoundTrip(*Request) (*Response, error) { panic(noHTTP2) }
38-
3935
type http2noDialH2RoundTripper struct{}
4036

4137
func (http2noDialH2RoundTripper) RoundTrip(*Request) (*Response, error) { panic(noHTTP2) }

src/net/http/transport.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,10 @@ func (pconn *persistConn) addTLS(name string, trace *httptrace.ClientTrace) erro
15311531
return nil
15321532
}
15331533

1534+
type erringRoundTripper interface {
1535+
RoundTripErr() error
1536+
}
1537+
15341538
func (t *Transport) dialConn(ctx context.Context, cm connectMethod) (pconn *persistConn, err error) {
15351539
pconn = &persistConn{
15361540
t: t,
@@ -1697,9 +1701,9 @@ func (t *Transport) dialConn(ctx context.Context, cm connectMethod) (pconn *pers
16971701
if s := pconn.tlsState; s != nil && s.NegotiatedProtocolIsMutual && s.NegotiatedProtocol != "" {
16981702
if next, ok := t.TLSNextProto[s.NegotiatedProtocol]; ok {
16991703
alt := next(cm.targetAddr, pconn.conn.(*tls.Conn))
1700-
if e, ok := alt.(http2erringRoundTripper); ok {
1704+
if e, ok := alt.(erringRoundTripper); ok {
17011705
// pconn.conn was closed by next (http2configureTransport.upgradeFn).
1702-
return nil, e.err
1706+
return nil, e.RoundTripErr()
17031707
}
17041708
return &persistConn{t: t, cacheKey: pconn.cacheKey, alt: alt}, nil
17051709
}

0 commit comments

Comments
 (0)