Merge pull request #2424 from Veirt/fix/http11-retry-fallback-2240

fix(httpx): keep retry fallback on HTTP/1.1 when -pr http11 is set
This commit is contained in:
Mzack9999
2026-03-19 16:49:49 +01:00
committed by GitHub
2 changed files with 24 additions and 1 deletions
+5 -1
View File
@@ -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{}
@@ -183,6 +183,10 @@ func New(options *Options) (*HTTPX, error) {
CheckRedirect: redirectFunc,
}, retryablehttpOptions)
if httpx.Options.Protocol == HTTP11 {
httpx.client.HTTPClient2 = httpx.client.HTTPClient
}
transport2 := &http2.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
+19
View File
@@ -28,3 +28,22 @@ func TestDo(t *testing.T) {
require.Greater(t, len(resp.Raw), 800)
})
}
func TestHTTP11DisablesRetryableHTTP2FallbackClient(t *testing.T) {
options := DefaultOptions
options.Protocol = HTTP11
ht, err := New(&options)
require.NoError(t, err)
require.NotNil(t, ht.client)
require.Same(t, ht.client.HTTPClient, ht.client.HTTPClient2)
}
func TestDefaultProtocolKeepsRetryableHTTP2FallbackClient(t *testing.T) {
options := DefaultOptions
ht, err := New(&options)
require.NoError(t, err)
require.NotNil(t, ht.client)
require.NotSame(t, ht.client.HTTPClient, ht.client.HTTPClient2)
}