From 67c95149814eede9909916277fd6b29d2e07d58c Mon Sep 17 00:00:00 2001 From: drmabus Date: Thu, 19 Mar 2026 12:08:10 +0700 Subject: [PATCH 1/4] fix: respect -pr http11 during retryablehttp fallback --- common/httpx/httpx.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common/httpx/httpx.go b/common/httpx/httpx.go index 039f4c4c..d08a23a1 100644 --- a/common/httpx/httpx.go +++ b/common/httpx/httpx.go @@ -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, From 470707293b1d89756de0ba5c6b457bb6384ec44f Mon Sep 17 00:00:00 2001 From: drmabus Date: Thu, 19 Mar 2026 12:24:59 +0700 Subject: [PATCH 2/4] fix: use HTTP11 constant instead of string literal --- common/httpx/httpx.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/httpx/httpx.go b/common/httpx/httpx.go index d08a23a1..f174da2d 100644 --- a/common/httpx/httpx.go +++ b/common/httpx/httpx.go @@ -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{} @@ -186,7 +186,7 @@ func New(options *Options) (*HTTPX, error) { // 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" { + if httpx.Options.Protocol == HTTP11 { httpx.client.HTTPClient2 = httpx.client.HTTPClient } From 50997c113daa783ddc692308c249622ae5790adf Mon Sep 17 00:00:00 2001 From: drmabus Date: Thu, 19 Mar 2026 12:35:09 +0700 Subject: [PATCH 3/4] test: add HTTP11 fallback regression tests --- common/httpx/httpx_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/common/httpx/httpx_test.go b/common/httpx/httpx_test.go index 7da6ad12..8d76f8b5 100644 --- a/common/httpx/httpx_test.go +++ b/common/httpx/httpx_test.go @@ -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.Equal(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.NotEqual(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) From 92ec35cc1a73044664ba176de0c3d17e3ef4a1b9 Mon Sep 17 00:00:00 2001 From: drmabus Date: Thu, 19 Mar 2026 12:43:44 +0700 Subject: [PATCH 4/4] test: use Same/NotSame for pointer identity in HTTP11 fallback tests --- common/httpx/httpx_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/httpx/httpx_test.go b/common/httpx/httpx_test.go index 8d76f8b5..7ee589a6 100644 --- a/common/httpx/httpx_test.go +++ b/common/httpx/httpx_test.go @@ -13,14 +13,14 @@ func TestHTTP11ProtocolDisablesHTTP2Fallback(t *testing.T) { opts.Protocol = HTTP11 ht, err := New(&opts) require.Nil(t, err) - require.Equal(t, ht.client.HTTPClient, ht.client.HTTPClient2, + 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.NotEqual(t, ht.client.HTTPClient, ht.client.HTTPClient2, + require.NotSame(t, ht.client.HTTPClient, ht.client.HTTPClient2, "HTTPClient2 should differ from HTTPClient with default protocol") }