Skip to content

Commit 4123be4

Browse files
committed
net/http: enable HTTP/2 support in DefaultTransport
The GODEBUG option remains, for now, but only for turning it off. We'll decide what to do with it before release. This CL includes the dependent http2 change (https://golang.org/cl/16692) in the http2 bundle (h2_bundle.go). Updates #6891 Change-Id: If9723ef627c7ba4f7343dc8cb89ca88ef0fbcb10 Reviewed-on: https://go-review.googlesource.com/16693 Reviewed-by: Blake Mizerany <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 4b7d5f0 commit 4123be4

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

src/net/http/h2_bundle.go

Lines changed: 21 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/net/http/transport.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,21 @@ var DefaultTransport RoundTripper = &Transport{
4444
ExpectContinueTimeout: 1 * time.Second,
4545
}
4646

47+
// Wire up HTTP/2 support to the DefaultTransport, unless GODEBUG=h2client=0.
4748
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") {
5250
return
5351
}
54-
5552
t := DefaultTransport.(*Transport)
56-
57-
// TODO(bradfitz,adg): move all this up to DefaultTransport before Go 1.6:
5853
t.RegisterProtocol("https", noDialH2Transport{h2DefaultTransport})
5954
t.TLSClientConfig = &tls.Config{
6055
NextProtos: []string{"h2"},
6156
}
6257
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+
},
6462
}
6563
}
6664

@@ -69,14 +67,11 @@ func init() {
6967
type noDialH2Transport struct{ rt *http2Transport }
7068

7169
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
8075
}
8176

8277
// DefaultMaxIdleConnsPerHost is the default value of Transport's

0 commit comments

Comments
 (0)