Skip to content

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

Closed
mcollina wants to merge 1 commit into
mainfrom
proxy-agent-use-pool
Closed

perf: use Pool instead of Client in ProxyAgent for HTTP proxy connections#4359
mcollina wants to merge 1 commit into
mainfrom
proxy-agent-use-pool

Conversation

@mcollina
Copy link
Copy Markdown
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 <noreply@anthropic.com>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Then this PR is not needed

Copy link
Copy Markdown
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

@mcollina mcollina closed this Jul 29, 2025
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