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) +}