From f9d0caa6dd8c1025427b849cdffe62ffa071f0bd Mon Sep 17 00:00:00 2001 From: OpenClaw Assistant Date: Sat, 7 Mar 2026 06:11:12 +0800 Subject: [PATCH] fix(httpx): preserve -pr http11 by disabling HTTP/2 fallback client --- common/httpx/httpx.go | 9 +++++++++ common/httpx/httpx_test.go | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/common/httpx/httpx.go b/common/httpx/httpx.go index 256066b2..cc0a0cd0 100644 --- a/common/httpx/httpx.go +++ b/common/httpx/httpx.go @@ -183,6 +183,11 @@ func New(options *Options) (*HTTPX, error) { CheckRedirect: redirectFunc, }, retryablehttpOptions) + if httpx.Options.Protocol == "http11" { + // keep retry fallback on the same client so explicit HTTP/1.1 is preserved + httpx.client.HTTPClient2 = httpx.client.HTTPClient + } + transport2 := &http2.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, @@ -455,3 +460,7 @@ func (httpx *HTTPX) Sanitize(respStr string, trimLine, normalizeSpaces bool) str } return respStr } + + + + diff --git a/common/httpx/httpx_test.go b/common/httpx/httpx_test.go index 7da6ad12..99f235c8 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 TestHTTP11ProtocolDisablesHTTP2FallbackClient(t *testing.T) { + opts := DefaultOptions + opts.Protocol = HTTP11 + + ht, err := New(&opts) + require.Nil(t, err) + require.NotNil(t, ht.client) + require.Equal(t, ht.client.HTTPClient, ht.client.HTTPClient2) +}