Skip to content

fix(runner): Ensure -pr/--protocol flag is correctly applied#2234

Merged
Mzack9999 merged 2 commits intoprojectdiscovery:devfrom
khs-alt:protocal
Aug 12, 2025
Merged

fix(runner): Ensure -pr/--protocol flag is correctly applied#2234
Mzack9999 merged 2 commits intoprojectdiscovery:devfrom
khs-alt:protocal

Conversation

@khs-alt
Copy link
Contributor

@khs-alt khs-alt commented Aug 6, 2025

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.go to check that the value of
httpx.options.Protocol is applied correctly.

Before

When running go run ./cmd/httpx -pr http11 -u example.com, the flag value was ignored:

   httpx.Options.Protocol: 
   Protocol == "http11": false

After

With the fix, the same command correctly applies the flag value:

   httpx.Options.Protocol: http11
   Protocol == "http11": true

This ensures the command-line flag works as expected.

Summary by CodeRabbit

  • Chores

    • Ensure the selected protocol option is correctly applied during execution (no change to user workflow).
  • Documentation

    • Updated protocol flag help text to note http2 and http3 are experimental.

@coderabbitai
Copy link

coderabbitai bot commented Aug 6, 2025

Walkthrough

A single line was added in runner/runner.go within the New function to set httpxOptions.Protocol from options.Protocol (via httpx.Proto()); the protocol flag help text in runner/options.go was updated to mention http2/http3 as experimental. No other logic changed.

Changes

Cohort / File(s) Change Summary
Runner Protocol Assignment
runner/runner.go
Sets httpxOptions.Protocol = httpx.Proto(options.Protocol) in the New function to propagate the selected protocol into the HTTPX client config.
Protocol Flag Help Text
runner/options.go
Updated help/usage text for the --protocol (-pr) flag to mention http2 [experimental] and http3 [experimental]; no functional/validation 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
Loading

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Assessment against linked issues

Objective Addressed Explanation
Ensure -pr (--protocol) flag value is assigned to Options.Protocol (#2233)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Poem

In the warren I hopped, one line to apply,
Protocol captured, no more wondering why.
Flags now take root and the client agrees,
A tiny edit — big graceful ease.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb3b7f0 and 079732e.

📒 Files selected for processing (1)
  • runner/options.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • runner/options.go
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between faac44c and bb3b7f0.

📒 Files selected for processing (1)
  • runner/runner.go (1 hunks)

Comment on lines +180 to 181
httpxOptions.Protocol = httpx.Proto(options.Protocol)

Copy link

Choose a reason for hiding this comment

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

🛠️ 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.

Suggested change
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.

@Mzack9999 Mzack9999 self-requested a review August 12, 2025 17:48
Copy link
Member

@Mzack9999 Mzack9999 left a comment

Choose a reason for hiding this comment

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

@khs-alt Nice catch! Thanks for the PR!

@Mzack9999 Mzack9999 merged commit 1abcf2b into projectdiscovery:dev Aug 12, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-pr (--protocol) flag does not assign value to Options.Protocol

2 participants

Comments