Skip to content
Closed
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
9 changes: 8 additions & 1 deletion common/httpx/httpx.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func New(options *Options) (*HTTPX, error) {
DisableKeepAlives: true,
}

if httpx.Options.Protocol == "http11" {
if httpx.Options.Protocol == HTTP11 {
// disable http2
_ = os.Setenv("GODEBUG", "http2client=0")
transport.TLSNextProto = map[string]func(string, *tls.Conn) http.RoundTripper{}
Expand Down Expand Up @@ -183,6 +183,13 @@ func New(options *Options) (*HTTPX, error) {
CheckRedirect: redirectFunc,
}, retryablehttpOptions)

// When http11 is forced, override HTTPClient2 to also use the HTTP/1.1-only
// transport. Without this, retryablehttp silently falls back to HTTPClient2
// (which has HTTP/2 enabled) on certain transport errors, bypassing -pr http11.
if httpx.Options.Protocol == HTTP11 {
httpx.client.HTTPClient2 = httpx.client.HTTPClient
}

transport2 := &http2.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
Expand Down
16 changes: 16 additions & 0 deletions common/httpx/httpx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ import (
"github.com/stretchr/testify/require"
)

func TestHTTP11ProtocolDisablesHTTP2Fallback(t *testing.T) {
opts := DefaultOptions
opts.Protocol = HTTP11
ht, err := New(&opts)
require.Nil(t, err)
require.Same(t, ht.client.HTTPClient, ht.client.HTTPClient2,
"HTTPClient2 should equal HTTPClient when Protocol is HTTP11")
}

func TestDefaultProtocolKeepsHTTP2Fallback(t *testing.T) {
ht, err := New(&DefaultOptions)
require.Nil(t, err)
require.NotSame(t, ht.client.HTTPClient, ht.client.HTTPClient2,
"HTTPClient2 should differ from HTTPClient with default protocol")
}

func TestDo(t *testing.T) {
ht, err := New(&DefaultOptions)
require.Nil(t, err)
Expand Down