Skip to content

Commit 83b3c34

Browse files
sam的电脑sam的电脑
authored andcommitted
fix(httpx): enforce http11 retry path to avoid h2 fallback (#2240)
1 parent 4311f8b commit 83b3c34

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

common/httpx/httpx.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ func New(options *Options) (*HTTPX, error) {
182182
Timeout: httpx.Options.Timeout,
183183
CheckRedirect: redirectFunc,
184184
}, retryablehttpOptions)
185+
if httpx.Options.Protocol == HTTP11 {
186+
// Keep retryablehttp-go on HTTP/1.1 as well when it retries internally.
187+
httpx.client.HTTPClient2 = httpx.client.HTTPClient
188+
}
185189

186190
transport2 := &http2.Transport{
187191
TLSClientConfig: &tls.Config{

common/httpx/httpx_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,12 @@ func TestDo(t *testing.T) {
2828
require.Greater(t, len(resp.Raw), 800)
2929
})
3030
}
31+
32+
func TestHTTP11DisablesRetryableHTTP2Fallback(t *testing.T) {
33+
opts := DefaultOptions
34+
opts.Protocol = HTTP11
35+
36+
ht, err := New(&opts)
37+
require.NoError(t, err)
38+
require.Same(t, ht.client.HTTPClient, ht.client.HTTPClient2)
39+
}

0 commit comments

Comments
 (0)