Skip to content

feat: support HTTP_PROXY environment variable for default HTTP client - #2547

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
wwalt1a:feat/support-proxy-env-vars
Jan 3, 2026
Merged

feat: support HTTP_PROXY environment variable for default HTTP client#2547
seefs001 merged 1 commit into
QuantumNous:mainfrom
wwalt1a:feat/support-proxy-env-vars

Conversation

@wwalt1a

@wwalt1a wwalt1a commented Dec 29, 2025

Copy link
Copy Markdown
Contributor

Description

Enable the default HTTP client to respect HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environment variables by adding Proxy: http.ProxyFromEnvironment to the transport configuration.

Motivation

Currently, setting proxy environment variables in Docker Compose has no effect on API requests because the custom http.Transport in InitHttpClient() doesn't configure proxy support. Users have to manually set proxy URLs for each channel, which is tedious when managing hundreds of channels.

Changes

  • Modified service/http_client.go: Added Proxy: http.ProxyFromEnvironment to the default transport
  • This allows users to set global proxy via Docker environment variables:
    environment:
      - HTTP_PROXY=http://192.168.1.1:7890
      - HTTPS_PROXY=http://192.168.1.1:7890
      - NO_PROXY=localhost,127.0.0.1
    

Summary by CodeRabbit

  • New Features
    • Added proxy support to HTTP client configuration. The application now respects standard proxy environment variables for network requests.

✏️ Tip: You can customize this high-level summary in your review settings.

- Add Proxy: http.ProxyFromEnvironment to default transport
- Allow users to set global proxy via Docker environment variables
- Per-channel proxy settings still override global proxy
- Fully backward compatible
@coderabbitai

coderabbitai Bot commented Dec 29, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A new Proxy field is added to the HTTP transport in InitHttpClient, leveraging http.ProxyFromEnvironment to enable proxy configuration through standard environment variables (HTTP_PROXY, HTTPS_PROXY, NO_PROXY).

Changes

Cohort / File(s) Summary
HTTP Client Configuration
service/http_client.go
Added Proxy: http.ProxyFromEnvironment to HTTP transport to enable proxy configuration via environment variables

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related PRs

Suggested reviewers

  • seefs001

Poem

🐰 A proxy path, so clean and fair,
Environment whispers through the air,
No more walls to block the way,
Your traffic flows—hooray, hooray! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 accurately and concisely describes the main change: adding support for HTTP_PROXY environment variable to the default HTTP client through Proxy field configuration.
✨ Finishing touches
  • 📝 Generate docstrings

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
service/http_client.go (1)

137-145: Consider explicitly setting Proxy: nil for clarity.

The SOCKS5 transport correctly uses a custom DialContext to route traffic through the SOCKS5 proxy. For clarity and to prevent future confusion about proxy behavior, consider explicitly setting Proxy: nil to document that no additional HTTP/HTTPS proxy layer should be applied.

🔎 Optional clarification
 		client := &http.Client{
 			Transport: &http.Transport{
 				MaxIdleConns:        common.RelayMaxIdleConns,
 				MaxIdleConnsPerHost: common.RelayMaxIdleConnsPerHost,
 				ForceAttemptHTTP2:   true,
+				Proxy:               nil, // SOCKS5 handles proxying via custom dialer
 				DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
 					return dialer.Dial(network, addr)
 				},
 			},
 			CheckRedirect: checkRedirect,
 		}
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 48d358f and 04ea79c.

📒 Files selected for processing (1)
  • service/http_client.go
🔇 Additional comments (1)
service/http_client.go (1)

41-41: LGTM! Clean implementation of environment proxy support.

The addition of Proxy: http.ProxyFromEnvironment correctly enables the default HTTP client to respect standard proxy environment variables (HTTP_PROXY, HTTPS_PROXY, NO_PROXY). This is the idiomatic Go approach and fully backward compatible.

@seefs001
seefs001 merged commit f1ba624 into QuantumNous:main Jan 3, 2026
1 check passed
@seefs001 seefs001 mentioned this pull request Jan 3, 2026
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
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.

2 participants