bunjs supports#649
Open
tocha688 wants to merge 5 commits into
Open
Conversation
… fallback in server.ts Agent-Logs-Url: https://github.com/tocha688/proxy-chain/sessions/5e6f77bd-e7c9-4264-bdbb-7cee28af680f Co-authored-by: tocha688 <154045226+tocha688@users.noreply.github.com>
…comment Agent-Logs-Url: https://github.com/tocha688/proxy-chain/sessions/5e6f77bd-e7c9-4264-bdbb-7cee28af680f Co-authored-by: tocha688 <154045226+tocha688@users.noreply.github.com>
…ompatibility Agent-Logs-Url: https://github.com/tocha688/proxy-chain/sessions/8dea0a62-128b-44dd-aed9-3afe06cbc82a Co-authored-by: tocha688 <154045226+tocha688@users.noreply.github.com>
fix: ERR_TUNNEL_CONNECTION_FAILED — Bun.js + Node.js CONNECT tunnel compatibility
jancurn
pushed a commit
that referenced
this pull request
May 19, 2026
…as-request in server Inspired by #649. Two changes that let proxy-chain itself run under Bun when used as a library, independent of what the test harness can prove: 1. `src/chain.ts` no longer goes through `http.request().on('connect')` to reach the upstream proxy. Bun 1.3 implements http.request on top of fetch and (a) rejects RFC 7230 authority-form paths like `:443` with "fetch() URL is invalid", (b) swallows the 407/590-class upstream responses. We now open a raw `net` or `tls` socket, send the CONNECT line ourselves, parse the response header buffer, and hand the remaining bytes back via `socket.unshift`. `rawHeaders` is preserved on the synthetic IncomingMessage so `tunnelConnectResponded` subscribers (the anonymizeProxy listener test) keep working. 2. `Server.onRequest` falls back to `onConnect` when `request.method === 'CONNECT'`. Bun delivers CONNECT through the generic 'request' event for some client shapes; Node ignores this branch because it always uses the dedicated 'connect' event.
jancurn
pushed a commit
that referenced
this pull request
Jun 12, 2026
Three changes that make proxy-chain work as a library under Bun 1.3, inspired by the approach in #649: 1. `chain.ts` no longer tunnels through `http.request().on('connect')`. Bun implements `http.request` on top of `fetch()`, which (a) rejects RFC 7230 authority-form CONNECT paths like `:443` with "fetch() URL is invalid" and (b) swallows 407/590-class upstream responses. Instead we open a raw `net`/`tls` socket, write the CONNECT request ourselves, parse the response headers, and `unshift` any remaining bytes back as tunnel payload. The synthetic response object keeps `rawHeaders` so `tunnelConnectResponded`/`tunnelConnectFailed` subscribers see the same shape as before. TLS options configured on `httpsAgent` (custom `ca`, client certs) are honored by re-using the agent's stored constructor options for the direct connection. 2. `Server.onRequest` routes `CONNECT` requests to `onConnect`: Bun delivers CONNECT through the generic 'request' event for some client shapes instead of the dedicated 'connect' event. 3. `Server.getConnectionStats` returns `undefined` under Bun. Bun does not populate `socket.bytesRead`/`bytesWritten` on http sockets, so the stats would silently read as zero — better no stats than wrong stats. (`connectionClosed` events consequently carry `stats: undefined` on Bun.) Node behavior is unchanged: full e2e suite produces an identical pass/fail set to master baseline (2012 passing, same 174 pre-existing environment failures) on Node 22.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
bunjs supports