Browse Source

http2: make configureTransport return the new t2 transport as well

This is needed so another CL in the main repo can keep the pointer
around to pass through Transport.CloseIdleConnections from the http1
transport.

This CL doesn't modify the exported ConfigureTransport
signature. We'll use the private one in the standard library for
now. (since it gets bundled into the same package)

Updates golang/go#13975

Change-Id: I824e9ac4a44616c8c2a480f83bd3dc62bffc30e4
Reviewed-on: https://go-review.googlesource.com/18678
Reviewed-by: Andrew Gerrand <adg@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Brad Fitzpatrick 10 years ago
parent
commit
c92cdcb05f
3 changed files with 7 additions and 6 deletions
  1. 3 3
      http2/configure_transport.go
  2. 2 2
      http2/not_go16.go
  3. 2 1
      http2/transport.go

+ 3 - 3
http2/configure_transport.go

@@ -12,11 +12,11 @@ import (
 	"net/http"
 )
 
-func configureTransport(t1 *http.Transport) error {
+func configureTransport(t1 *http.Transport) (*Transport, error) {
 	connPool := new(clientConnPool)
 	t2 := &Transport{ConnPool: noDialClientConnPool{connPool}}
 	if err := registerHTTPSProtocol(t1, noDialH2RoundTripper{t2}); err != nil {
-		return err
+		return nil, err
 	}
 	if t1.TLSClientConfig == nil {
 		t1.TLSClientConfig = new(tls.Config)
@@ -48,7 +48,7 @@ func configureTransport(t1 *http.Transport) error {
 	} else {
 		m["h2"] = upgradeFn
 	}
-	return nil
+	return t2, nil
 }
 
 // registerHTTPSProtocol calls Transport.RegisterProtocol but

+ 2 - 2
http2/not_go16.go

@@ -8,6 +8,6 @@ package http2
 
 import "net/http"
 
-func configureTransport(t1 *http.Transport) error {
-	return errTransportVersion
+func configureTransport(t1 *http.Transport) (*Transport, error) {
+	return nil, errTransportVersion
 }

+ 2 - 1
http2/transport.go

@@ -113,7 +113,8 @@ var errTransportVersion = errors.New("http2: ConfigureTransport is only supporte
 // It requires Go 1.6 or later and returns an error if the net/http package is too old
 // or if t1 has already been HTTP/2-enabled.
 func ConfigureTransport(t1 *http.Transport) error {
-	return configureTransport(t1) // in configure_transport.go (go1.6) or go15.go
+	_, err := configureTransport(t1) // in configure_transport.go (go1.6) or not_go16.go
+	return err
 }
 
 func (t *Transport) connPool() ClientConnPool {