Conversation
There was a problem hiding this comment.
Pull request overview
This pull request attempts to enable HTTP_PROXY support for web tools by explicitly setting Transport: http.DefaultTransport on the http.Client used by BraveSearchProvider. The change is motivated by issue #413, which requests that the web_fetch tool honor HTTP_PROXY environment variables to allow operation in proxy-required environments.
Changes:
- Modified BraveSearchProvider to explicitly set
Transport: http.DefaultTransporton its http.Client
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
nikolasdehor
left a comment
There was a problem hiding this comment.
Thanks for the PR, mattn! The intent is right, but I believe this change doesn't actually address issue #413.
When Transport is nil on http.Client, Go already uses http.DefaultTransport (which includes Proxy: http.ProxyFromEnvironment). So the Brave, DuckDuckGo, and Perplexity search providers already respect HTTP_PROXY/HTTPS_PROXY — this line is effectively a no-op.
The actual problem is in WebFetchTool.Execute() (~line 416 of web.go), which constructs a custom http.Transport{} without setting the Proxy field:
Transport: &http.Transport{
MaxIdleConns: 10,
IdleConnTimeout: 30 * time.Second,
DisableCompression: false,
TLSHandshakeTimeout: 15 * time.Second,
},When you manually construct an http.Transport{}, the Proxy field defaults to nil (no proxy) — unlike http.DefaultTransport which sets Proxy: http.ProxyFromEnvironment.
The fix for #413 should be:
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment, // ADD THIS
MaxIdleConns: 10,
IdleConnTimeout: 30 * time.Second,
DisableCompression: false,
TLSHandshakeTimeout: 15 * time.Second,
},Would you be open to updating the PR to fix the WebFetchTool transport instead? That's the code path that issue #413 is specifically about. The Brave search client change here can be kept for explicitness, or dropped since it's a no-op — your call.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I changed PR to use http.NewClient(). Initializing |
9075d18 to
57d66f8
Compare
57d66f8 to
4bfa10f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (2)
pkg/tools/web.go:42
- Setting
Transport: http.DefaultTransporthere is redundant because leavingTransportas nil already useshttp.DefaultTransport(which honorsProxyFromEnvironment). This doesn’t match the PR description that says default transport disablesHTTP_PROXY; if the proxy bug is inWebFetchTool’s custom transport, consider removing this to avoid confusion or update the PR description accordingly.
client := http.NewClient()
client.Timeout = 10 * time.Second
resp, err := client.Do(req)
if err != nil {
pkg/tools/web.go:420
- There are existing tests for
WebFetchTool, but none cover proxy behavior. Since this PR is intended to ensureHTTP_PROXY/HTTPS_PROXYis honored, add a focused test that asserts requests are routed through a proxy when the env var is set (or refactor client creation into a helper that can be unit-tested).
client.Transport.MaxIdleConns = 10
client.Transport.IdleConnTimeout = 30 * time.Second
client.Transport.DisableCompression = false
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| resp, err := client.Do(req) | ||
| if err != nil { |
There was a problem hiding this comment.
net/http does not provide http.NewClient(), so this will not compile. Use &http.Client{Timeout: ...} (Transport left nil to use the default transport) or construct a client via an existing project helper if one exists.
| client := http.NewClient() | ||
| client.Timeout = 30 * time.Second |
There was a problem hiding this comment.
net/http has no http.NewClient() function; this change introduces a compilation error. Revert to &http.Client{Timeout: ...} (or use a valid helper) to keep proxy behavior intact.
| client := http.NewClient() | |
| client.Timeout = 30 * time.Second | |
| client := &http.Client{Timeout: 30 * time.Second} |
| client := http.NewClient() | ||
| client.Timeout = 60 * time.Second | ||
| client.Transport.MaxIdleConns = 10 | ||
| client.Transport.IdleConnTimeout = 30 * time.Second | ||
| client.Transport.DisableCompression = false | ||
| client.Transport.TLSHandshakeTimeout = 15 * time.Second | ||
| client.CheckRedirect = func(req *http.Request, via []*http.Request) error { | ||
| if len(via) >= 5 { | ||
| return fmt.Errorf("stopped after 5 redirects") | ||
| } | ||
| return nil | ||
| } | ||
|
|
There was a problem hiding this comment.
This block will not compile: http.NewClient() doesn’t exist in net/http, and http.Client.Transport is a RoundTripper interface so you can’t set MaxIdleConns/IdleConnTimeout fields on it directly. If the goal is to honor HTTP_PROXY, create a *http.Transport that uses http.ProxyFromEnvironment (or clone http.DefaultTransport and adjust the fields), then assign it to client.Transport.
| client := http.NewClient() | |
| client.Timeout = 60 * time.Second | |
| client.Transport.MaxIdleConns = 10 | |
| client.Transport.IdleConnTimeout = 30 * time.Second | |
| client.Transport.DisableCompression = false | |
| client.Transport.TLSHandshakeTimeout = 15 * time.Second | |
| client.CheckRedirect = func(req *http.Request, via []*http.Request) error { | |
| if len(via) >= 5 { | |
| return fmt.Errorf("stopped after 5 redirects") | |
| } | |
| return nil | |
| } | |
| transport := &http.Transport{ | |
| Proxy: http.ProxyFromEnvironment, | |
| MaxIdleConns: 10, | |
| IdleConnTimeout: 30 * time.Second, | |
| DisableCompression: false, | |
| TLSHandshakeTimeout: 15 * time.Second, | |
| } | |
| client := &http.Client{ | |
| Timeout: 60 * time.Second, | |
| Transport: transport, | |
| CheckRedirect: func(req *http.Request, via []*http.Request) error { | |
| if len(via) >= 5 { | |
| return fmt.Errorf("stopped after 5 redirects") | |
| } | |
| return nil | |
| }, | |
| } |
Fixes #413
📝 Description
web.go set nil to http.Client.Transport. This will cause the http.Client to use the default transport, this disable HTTP_PROXY use.
🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
📚 Technical Context (Skip for Docs)
🧪 Test Environment
📸 Evidence (Optional)
Click to view Logs/Screenshots
☑️ Checklist