Skip to content

feat: honor HTTP_PROXY/HTTPS_PROXY env vars when -proxy is unset#2493

Merged
Mzack9999 merged 1 commit into
devfrom
feat/proxy-env-vars
May 13, 2026
Merged

feat: honor HTTP_PROXY/HTTPS_PROXY env vars when -proxy is unset#2493
Mzack9999 merged 1 commit into
devfrom
feat/proxy-env-vars

Conversation

@dogancanbakir
Copy link
Copy Markdown
Member

@dogancanbakir dogancanbakir commented May 12, 2026

Summary

  • Fall back to http.ProxyFromEnvironment for the HTTP transport when -proxy is empty, picking up HTTP_PROXY / HTTPS_PROXY / NO_PROXY (and lowercase variants).
  • Headless launcher does the same lookup manually since chromedp does not read env.
  • SOCKS works via socks5:// URLs in the same vars.

Closes #2492

Summary by CodeRabbit

  • New Features

    • Proxy settings now automatically detect and use HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environment variables as fallback when not explicitly configured.
  • Documentation

    • Updated proxy flag help text to clarify environment variable fallback behavior.

Review Change Stack

Falls back to http.ProxyFromEnvironment for the HTTP transport and
reads the same vars manually for the headless launcher (chromedp
does not read env).

Closes #2492
@auto-assign auto-assign Bot requested a review from Mzack9999 May 12, 2026 12:24
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Walkthrough

This PR adds support for automatic proxy detection from environment variables (HTTP_PROXY, HTTPS_PROXY, http_proxy, https_proxy) across the HTTP transport layer and browser launcher. The changes enable environment-based proxy configuration similar to curl behavior, with updated CLI documentation reflecting the new fallback behavior.

Changes

Environment Variable Proxy Support

Layer / File(s) Summary
HTTP transport proxy fallback
common/httpx/httpx.go
When neither HTTPProxy nor SocksProxy options are provided, transport.Proxy is set to http.ProxyFromEnvironment, enabling the Go HTTP client to read standard proxy environment variables.
Browser proxy auto-detection
runner/headless.go
NewBrowser auto-detects proxy from environment by checking HTTPS_PROXY, https_proxy, HTTP_PROXY, and http_proxy in order, using the first non-empty value as the proxy configuration.
CLI flag documentation
runner/options.go
The --proxy flag description is updated to document fallback to HTTP_PROXY/HTTPS_PROXY/NO_PROXY environment variables.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A carrot-colored proxy path,
Environment variables do the math,
No flag needed, just let it flow,
HTTP_PROXY helps us go,
From curl's example, httpx did grow! 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: adding support for HTTP_PROXY/HTTPS_PROXY environment variables as a fallback when the -proxy flag is unset.
Linked Issues check ✅ Passed The pull request implements all requirements from issue #2492: it enables httpx to automatically read HTTP_PROXY/HTTPS_PROXY/NO_PROXY environment variables (and lowercase variants) when -proxy is unset, similar to curl behavior.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing environment variable proxy detection: httpx transport setup, headless browser launcher proxy auto-detection, and command-line flag documentation updates.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/proxy-env-vars

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

@dogancanbakir dogancanbakir self-assigned this May 12, 2026
Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@runner/headless.go`:
- Around line 87-94: The current logic collapses proxies into a single proxy
value and ignores NO_PROXY; update the proxy resolution to read
HTTP_PROXY/https_proxy and HTTPS_PROXY/https_proxy separately along with
NO_PROXY/no_proxy, and when any are present use the existing Set() path (not
.Proxy()) to add Chromium flags: construct
--proxy-server="http=HTTP_PROXY;https=HTTPS_PROXY" using only the schemes that
exist (omit missing schemes) and add --proxy-bypass-list="NO_PROXY_VALUE" when
NO_PROXY is set; ensure you still respect an already-set proxy variable (proxy)
if provided but prefer explicit per-scheme env vars when present and remove the
.Proxy() call in favor of setting these flags via Set().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5192cae7-ec23-4cb2-bf4c-fde6ac107830

📥 Commits

Reviewing files that changed from the base of the PR and between 31af5c0 and 7f19af2.

📒 Files selected for processing (3)
  • common/httpx/httpx.go
  • runner/headless.go
  • runner/options.go

Comment thread runner/headless.go
Comment on lines +87 to +94
if proxy == "" {
for _, k := range []string{"HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"} {
if v := os.Getenv(k); v != "" {
proxy = v
break
}
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

`For go-rod v0.116.2 / Chromium launch flags, what is the correct way to:

  1. apply different HTTP_PROXY and HTTPS_PROXY values, and
  2. honor NO_PROXY/no_proxy via proxy bypass settings
    when launching Chrome?`

💡 Result:

To launch Chromium with go-rod v0.116.2 using different HTTP_PROXY and HTTPS_PROXY values, and honoring NO_PROXY/no_proxy bypasses: Use the launcher.Set method with Chromium's --proxy-server flag for scheme-specific proxies, and --proxy-bypass-list for bypass rules matching NO_PROXY format. Example code: import ( \"github.com/go-rod/rod/lib/launcher\" \"github.com/go-rod/rod/lib/launcher/flags\" \"github.com/go-rod/rod\" ) httpProxy := \"http://http-proxy-host:8080\" httpsProxy := \"http://https-proxy-host:8443\" noProxy := \"localhost,127.0.0.1,.example.com\" // matches NO_PROXY env var format, comma-separated l := launcher.New(). Set(\"--proxy-server\", \"http=\"+httpProxy+\";https=\"+httpsProxy). Set(\"--proxy-bypass-list\", noProxy). Headless(true) // or false controlURL := l.MustLaunch() defer l.Cleanup() browser := rod.New().ControlURL(controlURL).MustConnect() defer browser.MustClose() // Test page := browser.MustPage(\"https://httpbin.org/ip\") println(page.MustElement(\"body\").MustText()) Key points: - --proxy-server="http=PROXY;https=PROXY" sets different proxies for HTTP vs HTTPS schemes [1][2][3][4]. - --proxy-bypass-list="host1,host2,domain.com" bypasses proxy for matching hosts/domains (semicolon or comma separated), directly honors NO_PROXY format [5][1][6][7]. - Use launcher.Proxy(PROXY) or launcher.Set(flags.ProxyServer, PROXY) for single proxy [3][8][6]. - Environment variables like HTTP_PROXY are not directly used by Chromium command line; flags override [9][10]. - For auth, embed in proxy URL like "http://user:pass@host:port\" [8][11], or use browser.MustHandleAuth [3]. - Confirmed in go-rod examples and issues for v0.116.x [6][3][12].

Citations:


🏁 Script executed:

# View the actual code at lines 87-94 in runner/headless.go
head -95 runner/headless.go | tail -20

Repository: projectdiscovery/httpx

Length of output: 641


🏁 Script executed:

# Search for NO_PROXY handling in the file
rg -n "NO_PROXY|no_proxy" runner/headless.go

Repository: projectdiscovery/httpx

Length of output: 48


🏁 Script executed:

# Search for any proxy-related environment variable handling in the repository
rg -n "HTTP_PROXY|HTTPS_PROXY|proxy" runner/headless.go -A 2 -B 2

Repository: projectdiscovery/httpx

Length of output: 542


🏁 Script executed:

# Search for chromeLauncher.Proxy usage and context in the file
rg -n "Proxy" runner/headless.go -B 2 -A 2

Repository: projectdiscovery/httpx

Length of output: 153


🏁 Script executed:

# Check if there's any TODO or FIXME related to proxy handling
rg -n "TODO|FIXME|proxy|PROXY" runner/headless.go

Repository: projectdiscovery/httpx

Length of output: 446


🏁 Script executed:

# Check the go.mod or imports to understand which go-rod version is being used
fd "go.mod" | head -5 | xargs cat

Repository: projectdiscovery/httpx

Length of output: 8886


🏁 Script executed:

# Search for .Set usage with chromeLauncher in the file
rg -n "chromeLauncher\." runner/headless.go -A 1

Repository: projectdiscovery/httpx

Length of output: 364


🏁 Script executed:

# Check for launcher package imports and usage patterns
rg -n "launcher\." runner/headless.go | head -20

Repository: projectdiscovery/httpx

Length of output: 170


Headless env-proxy resolution drops NO_PROXY and collapses HTTP/HTTPS into one proxy.

Lines 87–94 pick a single env proxy and never consider NO_PROXY/no_proxy. This can route hosts through the proxy that should bypass it, and mishandles setups where HTTP_PROXY and HTTPS_PROXY differ.

Chromium requires --proxy-server="http=PROXY;https=PROXY" (scheme-specific) and --proxy-bypass-list="..." to honor NO_PROXY. The .Set() mechanism already exists in the code (line 100); use it to construct and pass these flags from the environment variables instead of collapsing them into a single .Proxy() call.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@runner/headless.go` around lines 87 - 94, The current logic collapses proxies
into a single proxy value and ignores NO_PROXY; update the proxy resolution to
read HTTP_PROXY/https_proxy and HTTPS_PROXY/https_proxy separately along with
NO_PROXY/no_proxy, and when any are present use the existing Set() path (not
.Proxy()) to add Chromium flags: construct
--proxy-server="http=HTTP_PROXY;https=HTTPS_PROXY" using only the schemes that
exist (omit missing schemes) and add --proxy-bypass-list="NO_PROXY_VALUE" when
NO_PROXY is set; ensure you still respect an already-set proxy variable (proxy)
if provided but prefer explicit per-scheme env vars when present and remove the
.Proxy() call in favor of setting these flags via Set().

@Mzack9999 Mzack9999 merged commit 6c34d93 into dev May 13, 2026
15 checks passed
@Mzack9999 Mzack9999 deleted the feat/proxy-env-vars branch May 13, 2026 19:24
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.

Support http_proxy / https_proxy vars

2 participants