Skip to content

Comments

fix(httpx): honor -pr http11 in h2 probe client#2416

Open
wh0amibjm wants to merge 2 commits intoprojectdiscovery:devfrom
wh0amibjm:fix/algora-2240-http11-no-h2-fallback-followup
Open

fix(httpx): honor -pr http11 in h2 probe client#2416
wh0amibjm wants to merge 2 commits intoprojectdiscovery:devfrom
wh0amibjm:fix/algora-2240-http11-no-h2-fallback-followup

Conversation

@wh0amibjm
Copy link

@wh0amibjm wh0amibjm commented Feb 20, 2026

Follow-up to #2414 and issue #2240.

This patch ensures explicit -pr http11 is honored across both retry fallback and HTTP/2 probe paths:

  • sets httpx.client2 = httpx.client.HTTPClient in HTTP11 mode
  • keeps dedicated HTTP/2 client only when protocol is not forced to HTTP11
  • adds/updates tests for both behaviors
  • adds dialer cleanup via t.Cleanup in protocol tests

Validation:

go test ./common/httpx -run TestNew_ -count=1

/claim #2240

Summary by CodeRabbit

  • New Features

    • New HTTP/1.1 mode that disables HTTP/2 fallback and uses a single shared client for HTTP/1.1 requests.
    • Protocol selection now determines whether a dedicated HTTP/2 transport is created.
  • Tests

    • Added unit tests validating behavior for HTTP/1.1 (shared client) and non-HTTP/1.1 (dedicated HTTP/2 transport).

@neo-by-projectdiscovery-dev
Copy link

neo-by-projectdiscovery-dev bot commented Feb 20, 2026

Neo - PR Security Review

No security issues found

Highlights

  • Test assertions at lines 30-33 properly validate that both client.HTTPClient2 and client2 reference the same HTTP/1.1 transport when protocol is forced
  • The incremental diff contains only test improvements and no changes to production security-sensitive code paths
Hardening Notes
  • Test assertions at lines 30-33 properly validate that both client.HTTPClient2 and client2 reference the same HTTP/1.1 transport when protocol is forced
  • The incremental diff contains only test improvements and no changes to production security-sensitive code paths

Comment @neo help for available commands. · Open in Neo

@coderabbitai
Copy link

coderabbitai bot commented Feb 20, 2026

Walkthrough

Replaces 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

Cohort / File(s) Summary
Core HTTP client behavior
common/httpx/httpx.go
Switches protocol check from literal "http11" to HTTP11 constant; when HTTP11 is selected, assigns HTTPClient2 and client2 to the primary HTTPClient (skipping separate http2.Transport creation); retains existing SNI, proxy, and TLS handling in other branches.
Protocol tests
common/httpx/httpx_protocol_test.go
Adds two tests: one asserting HTTP/1.1 mode reuses the same client and no http2.Transport is created; another asserting non-HTTP/1.1 mode creates a distinct http2.Transport and separate client.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I tunneled through options, found a neat switch,
HTTP/1.1 snugly reuses the same stitch,
HTTP/2 keeps its bouncy new gear,
Tests hop along to make it clear,
A tiny change, a confident twitch.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(httpx): honor -pr http11 in h2 probe client' accurately and specifically describes the main change—ensuring the HTTP/1.1 protocol flag is respected in the HTTP/2 probe client path, which aligns with the core modifications across both httpx.go and the test files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
common/httpx/httpx.go (1)

186-206: Use the HTTP11 typed constant instead of the "http11" string literal

The test file uses opts.Protocol = HTTP11 (the typed Proto constant defined in proto.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.

@wh0amibjm
Copy link
Author

Addressed CodeRabbit follow-up in 58e14d4:

  • replaced string literals with typed constant HTTP11 in protocol checks
  • added GODEBUG restore cleanup in TestNew_HTTP11DisablesRetryableHTTP2Fallback

Validation:

go test ./common/httpx -run TestNew_ -count=1

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

@wh0amibjm
Copy link
Author

Quick follow-up after latest bot review pass:

  • re-checked current branch (58e14d4) against prior actionable feedback
  • no remaining actionable review items detected on my side
  • tests for touched area still pass locally:
    • go test ./common/httpx -run TestNew_ -count=1

Ready for maintainer review/merge when convenient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants