From d0b7c16c05f37a8d5d124acdbecac860df0c58fb Mon Sep 17 00:00:00 2001 From: sharkqwy Date: Fri, 20 Feb 2026 16:24:32 +0800 Subject: [PATCH] fix: respect -pr http11 flag by disabling HTTP/2 fallback in retryablehttp When the user specifies -pr http11, httpx correctly disables HTTP/2 on the primary transport. However, retryablehttp-go's internal HTTPClient2 (used as a fallback when HTTP/1.x encounters HTTP/2 responses) still has HTTP/2 enabled, which silently upgrades connections and defeats the -pr flag. This fix sets HTTPClient2 to use the same HTTP/1.1-only transport when Protocol is 'http11', ensuring no HTTP/2 fallback occurs. Fixes #2240 --- common/httpx/httpx.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/common/httpx/httpx.go b/common/httpx/httpx.go index 039f4c4c..5bb542c3 100644 --- a/common/httpx/httpx.go +++ b/common/httpx/httpx.go @@ -183,6 +183,17 @@ func New(options *Options) (*HTTPX, error) { CheckRedirect: redirectFunc, }, retryablehttpOptions) + // When HTTP/1.1 is explicitly requested, also disable HTTP/2 fallback + // in the retryablehttp client's secondary HTTP client to prevent + // automatic HTTP/2 upgrade on retry (see retryablehttp-go do.go). + if httpx.Options.Protocol == "http11" { + httpx.client.HTTPClient2 = &http.Client{ + Transport: transport, + Timeout: httpx.Options.Timeout, + CheckRedirect: redirectFunc, + } + } + transport2 := &http2.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true,