fix(httpx): honor -pr http11 in h2 probe client#2416
fix(httpx): honor -pr http11 in h2 probe client#2416wh0amibjm wants to merge 2 commits intoprojectdiscovery:devfrom
Conversation
Neo - PR Security ReviewNo security issues found Highlights
Hardening Notes
Comment |
WalkthroughReplaces a string literal protocol check with a constant and conditionally reuses the primary HTTP client for HTTP/1.1 (disabling HTTP/2 transport creation); preserves previous HTTP/2 transport initialization for non-HTTP/1.1. Two tests validate both behaviors. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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.go (1)
186-206: Use theHTTP11typed constant instead of the"http11"string literalThe test file uses
opts.Protocol = HTTP11(the typedProtoconstant defined inproto.go), but the production code at lines 156 and 188 compares against the bare string"http11". Using the constant in both places keeps the comparison DRY and eliminates a silent mismatch risk if the constant value ever changes.♻️ Proposed change (applies to lines 156 and 188)
- if httpx.Options.Protocol == "http11" { + if httpx.Options.Protocol == HTTP11 { // ... protocol handling }🤖 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 - 206, Replace the string literal "http11" comparisons with the typed constant HTTP11 (the Proto constant defined in proto.go) so the checks use httpx.Options.Protocol == HTTP11 instead of == "http11"; update both locations where the literal is used (the branch deciding HTTP/1.1 mode and the related branch later in the file) to reference the HTTP11 constant to keep comparisons consistent and DRY.
🤖 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_protocol_test.go`:
- Around line 11-24: The test leaks a process-wide GODEBUG change because
New(&opts) with opts.Protocol = HTTP11 calls os.Setenv("GODEBUG",
"http2client=0") and never restores it; modify
TestNew_HTTP11DisablesRetryableHTTP2Fallback to capture the original
os.Getenv("GODEBUG") before calling New, and register a t.Cleanup that restores
the original value (use os.Setenv to restore non-empty original, or os.Unsetenv
if it was empty) so the GODEBUG setting is returned to its prior state after the
test; reference the New function, opts.Protocol/HTTP11 setup, and the
os.Setenv("GODEBUG", ...) side effect when applying the fix.
---
Nitpick comments:
In `@common/httpx/httpx.go`:
- Around line 186-206: Replace the string literal "http11" comparisons with the
typed constant HTTP11 (the Proto constant defined in proto.go) so the checks use
httpx.Options.Protocol == HTTP11 instead of == "http11"; update both locations
where the literal is used (the branch deciding HTTP/1.1 mode and the related
branch later in the file) to reference the HTTP11 constant to keep comparisons
consistent and DRY.
|
Addressed CodeRabbit follow-up in
Validation: go test ./common/httpx -run TestNew_ -count=1 |
There was a problem hiding this comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@common/httpx/httpx_protocol_test.go`:
- Around line 16-23: The code correctly uses os.LookupEnv to capture
originalGODEBUG and hadGODEBUG and restores state in t.Cleanup using os.Setenv
or os.Unsetenv; keep this implementation as-is (no change needed) and ensure the
variables originalGODEBUG, hadGODEBUG and the t.Cleanup block remain present so
an originally unset GODEBUG is restored to unset rather than set to an empty
string.
|
Quick follow-up after latest bot review pass:
Ready for maintainer review/merge when convenient. |
Follow-up to #2414 and issue #2240.
This patch ensures explicit
-pr http11is honored across both retry fallback and HTTP/2 probe paths:httpx.client2 = httpx.client.HTTPClientin HTTP11 modet.Cleanupin protocol testsValidation:
go test ./common/httpx -run TestNew_ -count=1/claim #2240
Summary by CodeRabbit
New Features
Tests