Skip to content

perf: use Pool instead of Client in ProxyAgent for HTTP proxy connections #4359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mcollina
Copy link
Member

Summary

  • Changed ProxyClient to use Pool instead of Client for HTTP proxy connections
  • Updated factory function to use Pool for non-tunneling scenarios
  • Added proper connector handling for CONNECT methods when tunneling is disabled

Benefits

  • Better connection management through connection pooling
  • Improved performance for HTTP proxy scenarios
  • Maintains all existing functionality and backward compatibility

Changes

  • ProxyClient constructor now uses new Pool() instead of new Client()
  • Added #connector field to store raw connector for CONNECT method handling
  • Updated factory function fallback to also use Pool
  • Cleaned up unused imports (kConnector, Client)

Test Plan

  • All existing proxy-agent tests pass
  • Linting passes
  • Both tunneling and non-tunneling scenarios work correctly

🤖 Generated with Claude Code

…ions

- ProxyClient now uses Pool instead of Client for better connection management
- Added connector storage for direct CONNECT method handling when tunneling is disabled
- Updated factory function to use Pool for non-tunneling HTTP-to-HTTP connections
- Maintains backward compatibility for both tunneling and non-tunneling scenarios
- Removes unused imports (kConnector, Client)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Matteo Collina <[email protected]>
@mcollina
Copy link
Member Author

cc @caitp (I know this now conflicts)

@mcollina mcollina requested a review from metcoder95 July 24, 2025 16:41
this.#client = new Client(origin, opts)
// Store the connector for direct socket connections
this.#connector = opts?.connect || buildConnector(opts)
this.#client = new Pool(origin, opts)
Copy link
Contributor

@caitp caitp Jul 24, 2025

Choose a reason for hiding this comment

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

the new Http1ProxyWrapper does this, although looking at the diff it's kind of clumbsy how it does it -- but the default factory it uses will make a Pool unless opts.connections === 1, which is pulled from the regular Agent factory.

I did switch to using a user supplied factory in order to get MockAgent tests passing, though. maybe it is a good simplification to just always create a Pool, though

Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

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

lgtm, just conflicts arised after previous PR merge

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.

3 participants