Skip to content

Commit

Permalink
Merge pull request #903 from stripe/brandur-disable-http2
Browse files Browse the repository at this point in the history
Disable HTTP/2 by default
  • Loading branch information
brandur-stripe authored Jul 25, 2019
2 parents 809b19b + 66c8fc0 commit e044438
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package stripe

import (
"bytes"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -944,7 +945,43 @@ var appInfo *AppInfo
var backends Backends
var encodedStripeUserAgent string
var encodedUserAgent string
var httpClient = &http.Client{Timeout: defaultHTTPTimeout}

// The default HTTP client used for communication with any of Stripe's
// backends.
//
// Can be overridden with the function `SetHTTPClient` or by setting the
// `HTTPClient` value when using `BackendConfig`.
var httpClient = &http.Client{
Timeout: defaultHTTPTimeout,

// There is a bug in Go's HTTP/2 implementation that occasionally causes it
// to send an empty body when it receives a `GOAWAY` message from a server:
//
// https://github.com/golang/go/issues/32441
//
// This is particularly problematic for this library because the empty body
// results in no parameters being sent, which usually results in a 400,
// which is a status code expressly not covered by retry logic.
//
// The bug seems to be somewhat tricky to fix and hasn't seen any traction
// lately, so for now we're mitigating by disabling HTTP/2 in stripe-go by
// default. Users who like to live dangerously can still re-enable it by
// specifying a custom HTTP client. When the bug above is fixed, we can
// turn it back on.
//
// The particular methodology here for disabling HTTP/2 is a little
// confusing at first glance, but is recommended by the `net/http`
// documentation ("Programs that must disable HTTP/2 can do so by setting
// Transport.TLSNextProto (for clients) ... to a non-nil, empty map.")
//
// Note that the test suite still uses HTTP/2 to run as it specifies its
// own HTTP client with it enabled. See `testing/testing.go`.
//
// (Written 2019/07/24.)
Transport: &http.Transport{
TLSNextProto: make(map[string]func(string, *tls.Conn) http.RoundTripper),
},
}

//
// Private functions
Expand Down

0 comments on commit e044438

Please sign in to comment.