Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable H/2 on the default HTTP client for Go 1.15+ #1156

Merged
merged 1 commit into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,11 @@ var httpClient = &http.Client{
// own HTTP client with it enabled. See `testing/testing.go`.
//
// (Written 2019/07/24.)
//
// UPDATE: With the release of Go 1.15, this bug has been fixed.
// As such, stripego115.go contains conditionally-compiled code that sets
// a different HTTP client as the default, since Go 1.15+ does not contain
// the aforementioned HTTP/2 bug.
Transport: &http.Transport{
TLSNextProto: make(map[string]func(string, *tls.Conn) http.RoundTripper),
},
Expand Down
28 changes: 28 additions & 0 deletions stripego115.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// +build go1.15

package stripe

import "net/http"

// This init block is only compiled on Go 1.15 and above
// (per https://golang.org/cmd/go/#hdr-Build_constraints).
//
// Go 1.15 fixes a long-standing bug https://github.com/golang/go/issues/32441
// that led to HTTP/2 being disabled by default in stripe-go
// in https://github.com/stripe/stripe-go/pull/903.
//
// This init is guaranteed to execute after all package-level var
// initializations have been completed, so the initialization of
// the `httpClient` package-level var will have completed before we
// run this init.
//
// Once stripe-go drops support for major Go versions below 1.15, this
// conditional build and init block should be removed, in favor of making
// this HTTP client the default.
func init() {

// Sets a default HTTP client that can utilize H/2 if the upstream supports it.
SetHTTPClient(&http.Client{
Timeout: defaultHTTPTimeout,
})
}