Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions common/httpx/httpx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -153,9 +152,8 @@ 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{}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

Expand All @@ -182,6 +180,10 @@ func New(options *Options) (*HTTPX, error) {
Timeout: httpx.Options.Timeout,
CheckRedirect: redirectFunc,
}, retryablehttpOptions)
if httpx.Options.Protocol == HTTP11 {
// Keep retryablehttp-go on HTTP/1.1 as well when it retries internally.
httpx.client.HTTPClient2 = httpx.client.HTTPClient
}

transport2 := &http2.Transport{
TLSClientConfig: &tls.Config{
Expand Down
17 changes: 17 additions & 0 deletions common/httpx/httpx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,20 @@ func TestDo(t *testing.T) {
require.Greater(t, len(resp.Raw), 800)
})
}

func TestHTTP11DisablesRetryableHTTP2Fallback(t *testing.T) {
opts := DefaultOptions
opts.Protocol = HTTP11

ht, err := New(&opts)
require.NoError(t, err)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
require.Same(t, ht.client.HTTPClient, ht.client.HTTPClient2)
}

func TestDefaultProtocolKeepsRetryableHTTP2Fallback(t *testing.T) {
opts := DefaultOptions

ht, err := New(&opts)
require.NoError(t, err)
require.NotSame(t, ht.client.HTTPClient, ht.client.HTTPClient2)
}