fix(runner): Ensure -pr/--protocol flag is correctly applied#2234
fix(runner): Ensure -pr/--protocol flag is correctly applied#2234Mzack9999 merged 2 commits intoprojectdiscovery:devfrom
Conversation
WalkthroughA single line was added in Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Runner.New
participant HTTPXOptions
User->>Runner.New: call New(...) with options (Protocol set)
Runner.New->>HTTPXOptions: httpx.Proto(options.Protocol) -> assign to Protocol
HTTPXOptions-->>Runner.New: configured httpxOptions with Protocol
Runner.New-->>User: returns Runner with configured httpxOptions
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes found. Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
| httpxOptions.Protocol = httpx.Proto(options.Protocol) | ||
|
|
There was a problem hiding this comment.
🛠️ Refactor suggestion
Guard the assignment to avoid clobbering the default protocol.
httpxOptions.Protocol is now unconditionally overwritten.
If the user omits -pr/--protocol, options.Protocol will be an empty string; httpx.Proto("") could map to an “unknown/zero” enum value, silently disabling the library’s default (currently inherited from httpx.DefaultOptions).
Safer pattern:
+// Preserve httpx.DefaultOptions.Protocol unless the flag was explicitly set
+if options.Protocol != "" {
+ httpxOptions.Protocol = httpx.Proto(options.Protocol)
+}
- httpxOptions.Protocol = httpx.Proto(options.Protocol)This keeps existing behaviour intact for callers that don’t pass the flag while still applying the fix when they do.
Also consider validating options.Protocol and surfacing an explicit error for unsupported values so mis-spelled inputs don’t fall through undetected.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| httpxOptions.Protocol = httpx.Proto(options.Protocol) | |
| // Preserve httpx.DefaultOptions.Protocol unless the flag was explicitly set | |
| if options.Protocol != "" { | |
| httpxOptions.Protocol = httpx.Proto(options.Protocol) | |
| } |
🤖 Prompt for AI Agents
In runner/runner.go around lines 180 to 181, the assignment to
httpxOptions.Protocol unconditionally overwrites the default protocol even when
options.Protocol is empty, which can disable the default silently. Fix this by
adding a guard to only assign httpxOptions.Protocol if options.Protocol is
non-empty. Additionally, add validation for options.Protocol to detect
unsupported or misspelled values and return an explicit error instead of
silently accepting them.
closes #2233
Description
This PR fixes a bug where the -pr or --protocol flag was being ignored.
Verification
I verified the fix by adding debug prints to
runner/runner.goto check that the value ofhttpx.options.Protocolis applied correctly.Before
When running
go run ./cmd/httpx -pr http11 -u example.com, the flag value was ignored:After
With the fix, the same command correctly applies the flag value:
This ensures the command-line flag works as expected.
Summary by CodeRabbit
Chores
Documentation