fix: honor -pr http11 by disabling retryable HTTP/2 fallback#2415
fix: honor -pr http11 by disabling retryable HTTP/2 fallback#2415shukwei899 wants to merge 1 commit intoprojectdiscovery:devfrom
Conversation
Neo Security AuditNo security issues found Highlights
Hardening Notes
Comment |
WalkthroughA new guard is added to the HTTP client initialization to explicitly handle HTTP/1.1 protocol requests by synchronizing the HTTP/2 client field, preventing unintended HTTP/2 fallback behavior during retries. Supporting tests validate both HTTP/1.1 and default protocol scenarios. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
common/httpx/httpx_test.go (1)
33-55: Add cleanup to both tests to close the fastdialer.Dialer
New()creates afastdialer.Dialer(stored inht.Dialer) which manages resources and should be released. Both tests are missing cleanup, which can cause resource leaks when running with-countor-race.♻️ Proposed fix — add cleanup to both tests
func TestHTTP11DisablesRetryHTTP2Fallback(t *testing.T) { opts := DefaultOptions opts.Timeout = 2 * time.Second opts.Protocol = "http11" ht, err := New(&opts) require.NoError(t, err) + t.Cleanup(func() { ht.Dialer.Close() }) require.NotNil(t, ht.client) require.NotNil(t, ht.client.HTTPClient) require.Same(t, ht.client.HTTPClient, ht.client.HTTPClient2) } func TestDefaultProtocolKeepsDedicatedHTTP2Client(t *testing.T) { opts := DefaultOptions opts.Timeout = 2 * time.Second ht, err := New(&opts) require.NoError(t, err) + t.Cleanup(func() { ht.Dialer.Close() }) require.NotNil(t, ht.client) require.NotNil(t, ht.client.HTTPClient) require.NotNil(t, ht.client.HTTPClient2) require.NotSame(t, ht.client.HTTPClient, ht.client.HTTPClient2) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@common/httpx/httpx_test.go` around lines 33 - 55, Both tests create an ht via New(...) which allocates a fastdialer.Dialer at ht.Dialer but never releases it; add cleanup to close the dialer after creation. In TestHTTP11DisablesRetryHTTP2Fallback and TestDefaultProtocolKeepsDedicatedHTTP2Client, after verifying err==nil and ht != nil, defer closing the dialer (e.g. defer ht.Dialer.Close() or check ht.Dialer != nil then close) so resources are always released even on test failures.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@common/httpx/httpx.go`:
- Around line 186-190: The guard checking httpx.client != nil before assigning
HTTPClient2 is redundant because NewWithHTTPClient always returns a non-nil
*retryablehttp.Client; remove the nil check and simplify the block to only test
httpx.Options.Protocol == "http11" and then set httpx.client.HTTPClient2 =
httpx.client.HTTPClient (referencing httpx.Options.Protocol, httpx.client,
HTTPClient and HTTPClient2) so the intent (prevent falling back to HTTP/2) is
preserved without the unnecessary nil condition.
---
Nitpick comments:
In `@common/httpx/httpx_test.go`:
- Around line 33-55: Both tests create an ht via New(...) which allocates a
fastdialer.Dialer at ht.Dialer but never releases it; add cleanup to close the
dialer after creation. In TestHTTP11DisablesRetryHTTP2Fallback and
TestDefaultProtocolKeepsDedicatedHTTP2Client, after verifying err==nil and ht !=
nil, defer closing the dialer (e.g. defer ht.Dialer.Close() or check ht.Dialer
!= nil then close) so resources are always released even on test failures.
| // When HTTP/1.1 is explicitly requested, prevent retryablehttp from | ||
| // falling back to HTTP/2 on malformed response retries. | ||
| if httpx.Options.Protocol == "http11" && httpx.client != nil { | ||
| httpx.client.HTTPClient2 = httpx.client.HTTPClient | ||
| } |
There was a problem hiding this comment.
Redundant httpx.client != nil guard
retryablehttp.Client holds both HTTPClient and HTTPClient2 as exported fields; NewWithHTTPClient always returns a fully-initialised, non-nil pointer. The httpx.client != nil branch condition is therefore always true and adds noise without a safety benefit. The protocol check alone is sufficient:
🛠️ Proposed simplification
- if httpx.Options.Protocol == "http11" && httpx.client != nil {
+ if httpx.Options.Protocol == "http11" {
httpx.client.HTTPClient2 = httpx.client.HTTPClient
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@common/httpx/httpx.go` around lines 186 - 190, The guard checking
httpx.client != nil before assigning HTTPClient2 is redundant because
NewWithHTTPClient always returns a non-nil *retryablehttp.Client; remove the nil
check and simplify the block to only test httpx.Options.Protocol == "http11" and
then set httpx.client.HTTPClient2 = httpx.client.HTTPClient (referencing
httpx.Options.Protocol, httpx.client, HTTPClient and HTTPClient2) so the intent
(prevent falling back to HTTP/2) is preserved without the unnecessary nil
condition.
Proposed Changes
-pr http11is selected, force retryablehttp to reuse the same HTTP/1.1 client for fallback retriesHTTPClientandHTTPClient2Proof
Checklist
dev)/claim #2240
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests