-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(httpx): honor -pr http11 in h2 probe client #2416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,51 @@ | ||||||||||||
| package httpx | ||||||||||||
|
|
||||||||||||
| import ( | ||||||||||||
| "os" | ||||||||||||
| "testing" | ||||||||||||
|
|
||||||||||||
| "golang.org/x/net/http2" | ||||||||||||
|
|
||||||||||||
| "github.com/stretchr/testify/require" | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| // TestNew_HTTP11DisablesRetryableHTTP2Fallback verifies that forcing HTTP/1.1 disables retryablehttp-go's HTTP/2 fallback and prevents HTTP/2 probing client creation. | ||||||||||||
| func TestNew_HTTP11DisablesRetryableHTTP2Fallback(t *testing.T) { | ||||||||||||
| opts := DefaultOptions | ||||||||||||
| opts.Protocol = HTTP11 | ||||||||||||
|
|
||||||||||||
| originalGODEBUG, hadGODEBUG := os.LookupEnv("GODEBUG") | ||||||||||||
| t.Cleanup(func() { | ||||||||||||
| if hadGODEBUG { | ||||||||||||
| _ = os.Setenv("GODEBUG", originalGODEBUG) | ||||||||||||
| } else { | ||||||||||||
| _ = os.Unsetenv("GODEBUG") | ||||||||||||
| } | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| ht, err := New(&opts) | ||||||||||||
| require.NoError(t, err) | ||||||||||||
| require.NotNil(t, ht) | ||||||||||||
| t.Cleanup(func() { ht.Dialer.Close() }) | ||||||||||||
| require.NotNil(t, ht.client) | ||||||||||||
| require.Same(t, ht.client.HTTPClient, ht.client.HTTPClient2) | ||||||||||||
| require.Same(t, ht.client.HTTPClient, ht.client2) | ||||||||||||
| _, isHTTP2 := ht.client2.Transport.(*http2.Transport) | ||||||||||||
| require.False(t, isHTTP2) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // TestNew_NonHTTP11KeepsRetryableHTTP2FallbackClient verifies that non-HTTP/1.1 mode keeps a dedicated HTTP/2 client2 transport and allows retryable fallback behavior. | ||||||||||||
| func TestNew_NonHTTP11KeepsRetryableHTTP2FallbackClient(t *testing.T) { | ||||||||||||
| opts := DefaultOptions | ||||||||||||
| opts.Protocol = HTTP2 | ||||||||||||
|
|
||||||||||||
| ht, err := New(&opts) | ||||||||||||
| require.NoError(t, err) | ||||||||||||
| require.NotNil(t, ht) | ||||||||||||
| t.Cleanup(func() { ht.Dialer.Close() }) | ||||||||||||
| require.NotNil(t, ht.client) | ||||||||||||
| require.NotSame(t, ht.client.HTTPClient, ht.client.HTTPClient2) | ||||||||||||
| require.NotSame(t, ht.client.HTTPClient, ht.client2) | ||||||||||||
| _, isHTTP2 := ht.client2.Transport.(*http2.Transport) | ||||||||||||
|
Comment on lines
+48
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a nil guard for
🛡️ Proposed fix require.NotSame(t, ht.client.HTTPClient, ht.client2)
+ require.NotNil(t, ht.client2)
_, isHTTP2 := ht.client2.Transport.(*http2.Transport)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| require.True(t, isHTTP2) | ||||||||||||
| } | ||||||||||||
Uh oh!
There was an error while loading. Please reload this page.