Skip to content

Preserve default transport settings for proxy clients#2343

Merged
luispater merged 1 commit intorouter-for-me:devfrom
kongkk233:fix/proxy-transport-defaults
Mar 28, 2026
Merged

Preserve default transport settings for proxy clients#2343
luispater merged 1 commit intorouter-for-me:devfrom
kongkk233:fix/proxy-transport-defaults

Conversation

@kongkk233
Copy link
Copy Markdown
Contributor

Summary

  • clone http.DefaultTransport before applying proxy settings
  • preserve default transport behavior for direct, HTTP proxy, and SOCKS5 proxy clients
  • add tests to verify proxy transports inherit key default transport settings

Why

Proxy-backed clients were created from near-empty http.Transport values, 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

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 http.DefaultTransport before applying their specific proxy configurations, this change guarantees consistent and robust behavior for direct, HTTP, and SOCKS5 proxy connections, preventing intermittent connection issues.

Highlights

  • Default Transport Inheritance: Introduced a new helper function cloneDefaultTransport to ensure http.DefaultTransport settings are consistently inherited by proxy clients.
  • Proxy Client Configuration: Updated NewDirectTransport and BuildHTTPTransport to clone http.DefaultTransport before applying proxy-specific configurations for direct, HTTP, and SOCKS5 proxies.
  • Test Coverage: Added comprehensive tests to verify that HTTP and SOCKS5 proxy transports correctly inherit key default settings like ForceAttemptHTTP2, IdleConnTimeout, and TLSHandshakeTimeout.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +129 to +138
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)
}
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.

medium

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.

Copy link
Copy Markdown
Collaborator

@luispater luispater left a comment

Choose a reason for hiding this comment

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

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.

@luispater luispater changed the base branch from main to dev March 28, 2026 12:57
@luispater luispater merged commit 1767a56 into router-for-me:dev Mar 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants