@@ -44,23 +44,21 @@ var DefaultTransport RoundTripper = &Transport{
44
44
ExpectContinueTimeout : 1 * time .Second ,
45
45
}
46
46
47
+ // Wire up HTTP/2 support to the DefaultTransport, unless GODEBUG=h2client=0.
47
48
func init () {
48
- // TODO(bradfitz,adg): remove the following line before Go 1.6
49
- // ships. This just gives us a mechanism to temporarily
50
- // enable the http2 client during development.
51
- if ! strings .Contains (os .Getenv ("GODEBUG" ), "h2client=1" ) {
49
+ if strings .Contains (os .Getenv ("GODEBUG" ), "h2client=0" ) {
52
50
return
53
51
}
54
-
55
52
t := DefaultTransport .(* Transport )
56
-
57
- // TODO(bradfitz,adg): move all this up to DefaultTransport before Go 1.6:
58
53
t .RegisterProtocol ("https" , noDialH2Transport {h2DefaultTransport })
59
54
t .TLSClientConfig = & tls.Config {
60
55
NextProtos : []string {"h2" },
61
56
}
62
57
t .TLSNextProto = map [string ]func (string , * tls.Conn ) RoundTripper {
63
- "h2" : http2TransportForConn ,
58
+ "h2" : func (authority string , c * tls.Conn ) RoundTripper {
59
+ h2DefaultTransport .AddIdleConn (authority , c )
60
+ return h2DefaultTransport
61
+ },
64
62
}
65
63
}
66
64
@@ -69,14 +67,11 @@ func init() {
69
67
type noDialH2Transport struct { rt * http2Transport }
70
68
71
69
func (t noDialH2Transport ) RoundTrip (req * Request ) (* Response , error ) {
72
- // TODO(bradfitz): wire up http2.Transport
73
- return nil , ErrSkipAltProtocol
74
- }
75
-
76
- func http2TransportForConn (authority string , c * tls.Conn ) RoundTripper {
77
- // TODO(bradfitz): donate c to h2DefaultTransport:
78
- // h2DefaultTransport.AddIdleConn(authority, c)
79
- return h2DefaultTransport
70
+ res , err := t .rt .RoundTripOpt (req , http2RoundTripOpt {OnlyCachedConn : true })
71
+ if err == http2ErrNoCachedConn {
72
+ return nil , ErrSkipAltProtocol
73
+ }
74
+ return res , err
80
75
}
81
76
82
77
// DefaultMaxIdleConnsPerHost is the default value of Transport's
0 commit comments