Preserve default transport settings for proxy clients#2343
Preserve default transport settings for proxy clients#2343luispater merged 1 commit intorouter-for-me:devfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue where proxy-backed HTTP clients were not inheriting essential default transport settings, leading to potential network instability. By ensuring that all proxy clients clone the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the proxyutil package to ensure that http.Transport instances created for direct, HTTP, and SOCKS5 proxies correctly inherit default settings from http.DefaultTransport. This is achieved by introducing a cloneDefaultTransport helper function. Corresponding test cases were updated and added to verify this inheritance behavior. The review suggests refactoring duplicated test assertions into a shared helper function to improve maintainability.
| defaultTransport := mustDefaultTransport(t) | ||
| if transport.ForceAttemptHTTP2 != defaultTransport.ForceAttemptHTTP2 { | ||
| t.Fatalf("ForceAttemptHTTP2 = %v, want %v", transport.ForceAttemptHTTP2, defaultTransport.ForceAttemptHTTP2) | ||
| } | ||
| if transport.IdleConnTimeout != defaultTransport.IdleConnTimeout { | ||
| t.Fatalf("IdleConnTimeout = %v, want %v", transport.IdleConnTimeout, defaultTransport.IdleConnTimeout) | ||
| } | ||
| if transport.TLSHandshakeTimeout != defaultTransport.TLSHandshakeTimeout { | ||
| t.Fatalf("TLSHandshakeTimeout = %v, want %v", transport.TLSHandshakeTimeout, defaultTransport.TLSHandshakeTimeout) | ||
| } |
There was a problem hiding this comment.
There's some code duplication here for checking the transport settings. This block of checks is also present in TestBuildHTTPTransportHTTPProxy (lines 100-109). To improve maintainability and avoid repetition, consider extracting this logic into a helper function.
For example, you could create a helper function like this:
func assertInheritsDefaultTransportSettings(t *testing.T, transport *http.Transport) {
t.Helper()
defaultTransport := mustDefaultTransport(t)
if transport.ForceAttemptHTTP2 != defaultTransport.ForceAttemptHTTP2 {
t.Fatalf("ForceAttemptHTTP2 = %v, want %v", transport.ForceAttemptHTTP2, defaultTransport.ForceAttemptHTTP2)
}
if transport.IdleConnTimeout != defaultTransport.IdleConnTimeout {
t.Fatalf("IdleConnTimeout = %v, want %v", transport.IdleConnTimeout, defaultTransport.IdleConnTimeout)
}
if transport.TLSHandshakeTimeout != defaultTransport.TLSHandshakeTimeout {
t.Fatalf("TLSHandshakeTimeout = %v, want %v", transport.TLSHandshakeTimeout, defaultTransport.TLSHandshakeTimeout)
}
}Then you could simply call assertInheritsDefaultTransportSettings(t, transport) in both this test and TestBuildHTTPTransportHTTPProxy.
luispater
left a comment
There was a problem hiding this comment.
Summary:
This PR cleanly fixes a real reliability issue by cloning http.DefaultTransport before applying proxy behavior. The scope is focused, and the implementation aligns with the stated goal.
Key findings:
- Blocking: none.
- Non-blocking: test coverage is strong for HTTP/SOCKS5 proxy paths; adding a direct-mode inheritance assertion would make coverage fully symmetric.
What changed well:
- Introduced a shared clone path for transport creation, preserving important default settings.
- Kept direct mode explicitly proxy-free (
Proxy = nil). - Updated SOCKS5 and HTTP proxy paths to inherit baseline transport behavior while applying proxy-specific wiring.
- Added targeted tests validating inherited transport defaults for proxy modes.
Test plan:
- Reported in PR:
go test ./sdk/proxyutil - Suggested follow-up: add direct-mode inheritance assertion test as noted above.
Recommendation:
Approve.
This is an automated Codex review result and still requires manual verification by a human reviewer.
Summary
http.DefaultTransportbefore applying proxy settingsWhy
Proxy-backed clients were created from near-empty
http.Transportvalues, which dropped important defaults such as idle connection handling, TLS handshake timeout, and HTTP/2 behavior. In unstable network/proxy environments this can surface as intermittent EOFs on outbound requests, especially for POST-based auth flows.Testing
go test ./sdk/proxyutil