Skip to content

Commit

Permalink
net/http: enable HTTP/2 support in DefaultTransport
Browse files Browse the repository at this point in the history
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 golang#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]>
  • Loading branch information
bradfitz committed Nov 7, 2015
1 parent 4b7d5f0 commit 4123be4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
23 changes: 21 additions & 2 deletions src/net/http/h2_bundle.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 11 additions & 16 deletions src/net/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,21 @@ var DefaultTransport RoundTripper = &Transport{
ExpectContinueTimeout: 1 * time.Second,
}

// Wire up HTTP/2 support to the DefaultTransport, unless GODEBUG=h2client=0.
func init() {
// TODO(bradfitz,adg): remove the following line before Go 1.6
// ships. This just gives us a mechanism to temporarily
// enable the http2 client during development.
if !strings.Contains(os.Getenv("GODEBUG"), "h2client=1") {
if strings.Contains(os.Getenv("GODEBUG"), "h2client=0") {
return
}

t := DefaultTransport.(*Transport)

// TODO(bradfitz,adg): move all this up to DefaultTransport before Go 1.6:
t.RegisterProtocol("https", noDialH2Transport{h2DefaultTransport})
t.TLSClientConfig = &tls.Config{
NextProtos: []string{"h2"},
}
t.TLSNextProto = map[string]func(string, *tls.Conn) RoundTripper{
"h2": http2TransportForConn,
"h2": func(authority string, c *tls.Conn) RoundTripper {
h2DefaultTransport.AddIdleConn(authority, c)
return h2DefaultTransport
},
}
}

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

func (t noDialH2Transport) RoundTrip(req *Request) (*Response, error) {
// TODO(bradfitz): wire up http2.Transport
return nil, ErrSkipAltProtocol
}

func http2TransportForConn(authority string, c *tls.Conn) RoundTripper {
// TODO(bradfitz): donate c to h2DefaultTransport:
// h2DefaultTransport.AddIdleConn(authority, c)
return h2DefaultTransport
res, err := t.rt.RoundTripOpt(req, http2RoundTripOpt{OnlyCachedConn: true})
if err == http2ErrNoCachedConn {
return nil, ErrSkipAltProtocol
}
return res, err
}

// DefaultMaxIdleConnsPerHost is the default value of Transport's
Expand Down

0 comments on commit 4123be4

Please sign in to comment.