Skip to content

feat(http-proxy-agent): emit 'proxyConnect' event#390

Open
abhu85 wants to merge 2 commits intoTooTallNate:mainfrom
abhu85:feat/http-proxy-agent-proxyconnect
Open

feat(http-proxy-agent): emit 'proxyConnect' event#390
abhu85 wants to merge 2 commits intoTooTallNate:mainfrom
abhu85:feat/http-proxy-agent-proxyconnect

Conversation

@abhu85
Copy link

@abhu85 abhu85 commented Feb 23, 2026

Summary

Fixes #368 - Emit the proxyConnect event for http-proxy-agent for parity with https-proxy-agent.

This PR adds proxyConnect event emission to http-proxy-agent. The event is emitted on both the request and the agent instance when the socket connects to the proxy server.

Changes

  • Added ProxyConnect interface with socket property
  • Emit proxyConnect event on the request after socket connects
  • Emit proxyConnect event on the agent instance after socket connects
  • Added test cases for both event emissions

Event Payload

Since http-proxy-agent doesn't use the CONNECT method (it sends requests directly through the proxy), the event payload is different from https-proxy-agent. The payload includes:

interface ProxyConnect {
  socket: net.Socket;
}

This gives users access to the connected socket so they can inspect connection details like remoteAddress, localPort, etc.

Usage Example

import { HttpProxyAgent } from 'http-proxy-agent';

const agent = new HttpProxyAgent('http://proxy:8080');

// Listen on the request
const req = http.request(url, { agent });
req.on('proxyConnect', (connect) => {
  console.log('Connected to proxy:', connect.socket.remoteAddress);
});

// Or listen on the agent
agent.on('proxyConnect', (connect, req) => {
  console.log('Proxy connection established');
});

Test Cases

  • should emit "proxyConnect" event on the request
  • should emit "proxyConnect" event on the agent

Adds `proxyConnect` event emission to `http-proxy-agent` for parity with
`https-proxy-agent`. The event is emitted on both the request and the
agent instance when the socket connects to the proxy server.

The event payload includes:
- `socket`: The connected socket to the proxy server

This allows users to access the socket connection details (remoteAddress,
localPort, etc.) when the proxy connection is established.

Fixes TooTallNate#368

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2026

🦋 Changeset detected

Latest commit: 78c1edf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
http-proxy-agent Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Feb 23, 2026

@abhu85 is attempting to deploy a commit to the Nathan Rajlich's projects Team on Vercel.

A member of the Team first needs to authorize it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

[http-proxy-agent] emit the 'proxyConnect' event

1 participant