From 16e61f194325ffdddc7d8e7c8d7e742703eb0e56 Mon Sep 17 00:00:00 2001 From: Tianlin0725 Date: Fri, 6 Mar 2026 02:02:31 +0800 Subject: [PATCH] fix(http11): disable retryable http2 fallback client --- common/httpx/httpx.go | 4 ++++ common/httpx/httpx_test.go | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/common/httpx/httpx.go b/common/httpx/httpx.go index 039f4c4ca..ecbc4c66e 100644 --- a/common/httpx/httpx.go +++ b/common/httpx/httpx.go @@ -183,6 +183,10 @@ func New(options *Options) (*HTTPX, error) { CheckRedirect: redirectFunc, }, retryablehttpOptions) + if httpx.Options.Protocol == "http11" { + httpx.client.HTTPClient2 = nil + } + transport2 := &http2.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, diff --git a/common/httpx/httpx_test.go b/common/httpx/httpx_test.go index 7da6ad12d..be22a85bc 100644 --- a/common/httpx/httpx_test.go +++ b/common/httpx/httpx_test.go @@ -28,3 +28,13 @@ func TestDo(t *testing.T) { require.Greater(t, len(resp.Raw), 800) }) } + +func TestHTTP11ShouldDisableRetryableHTTP2Fallback(t *testing.T) { + opts := DefaultOptions + opts.Protocol = "http11" + + ht, err := New(&opts) + require.NoError(t, err) + + require.Nil(t, ht.client.HTTPClient2, "when protocol is http11, retryablehttp HTTPClient2 fallback should be disabled") +}