mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
## Summary
Add `proxy` option to WebSocket constructor for connecting through HTTP
CONNECT proxies.
### Features
- Support for `ws://` and `wss://` through HTTP proxies
- Support for `ws://` and `wss://` through HTTPS proxies (with
`rejectUnauthorized: false`)
- Proxy authentication via URL credentials (Basic auth)
- Custom proxy headers support
- Full TLS options (`ca`, `cert`, `key`, etc.) for target connections
using `SSLConfig.fromJS`
### API
```javascript
// String format
new WebSocket("wss://example.com", { proxy: "http://proxy:8080" })
// With credentials
new WebSocket("wss://example.com", { proxy: "http://user:pass@proxy:8080" })
// Object format with custom headers
new WebSocket("wss://example.com", {
proxy: { url: "http://proxy:8080", headers: { "X-Custom": "value" } }
})
// HTTPS proxy
new WebSocket("ws://example.com", {
proxy: "https://proxy:8443",
tls: { rejectUnauthorized: false }
})
```
### Implementation
| File | Changes |
|------|---------|
| `WebSocketUpgradeClient.zig` | Proxy state machine and CONNECT
handling |
| `WebSocketProxyTunnel.zig` | **New** - TLS tunnel inside CONNECT for
wss:// through HTTP proxy |
| `JSWebSocket.cpp` | Parse proxy option and TLS options using
`SSLConfig.fromJS` |
| `WebSocket.cpp` | Pass proxy parameters to Zig, handle HTTPS proxy
socket selection |
| `bun.d.ts` | Add `proxy` and full TLS options to WebSocket types |
### Supported Scenarios
| Scenario | Status |
|----------|--------|
| ws:// through HTTP proxy | ✅ Working |
| wss:// through HTTP proxy | ✅ Working (TLS tunnel) |
| ws:// through HTTPS proxy | ✅ Working (with `rejectUnauthorized:
false`) |
| wss:// through HTTPS proxy | ✅ Working (with `rejectUnauthorized:
false`) |
| Proxy authentication (Basic) | ✅ Working |
| Custom proxy headers | ✅ Working |
| Custom CA for HTTPS proxy | ✅ Working |
## Test plan
- [x] API tests verify proxy option is accepted in various formats
- [x] Functional tests with local HTTP CONNECT proxy server
- [x] Proxy authentication tests (Basic auth)
- [x] HTTPS proxy tests with `rejectUnauthorized: false`
- [x] Error handling tests (auth failures, wrong credentials)
Run tests: `bun test test/js/web/websocket/websocket-proxy.test.ts`
## Changelog
- Added `proxy` option to `WebSocket` constructor for HTTP/HTTPS proxy
support
- Added full TLS options (`ca`, `cert`, `key`, `passphrase`, etc.) to
`WebSocket` constructor
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
127 lines
3.5 KiB
JSON
127 lines
3.5 KiB
JSON
{
|
|
"name": "test",
|
|
"devDependencies": {
|
|
"@types/react": "18.0.28",
|
|
"@types/react-dom": "18.0.11",
|
|
"@types/supertest": "2.0.12",
|
|
"@types/utf-8-validate": "5.0.0",
|
|
"@types/ws": "8.5.10",
|
|
"@types/puppeteer": "7.0.4"
|
|
},
|
|
"dependencies": {
|
|
"@astrojs/node": "9.1.3",
|
|
"@azure/service-bus": "7.9.4",
|
|
"@duckdb/node-api": "1.1.3-alpha.7",
|
|
"@electric-sql/pglite": "0.2.17",
|
|
"@fastify/websocket": "11.0.2",
|
|
"@grpc/grpc-js": "1.12.0",
|
|
"@grpc/proto-loader": "0.7.10",
|
|
"@happy-dom/global-registrator": "17.0.3",
|
|
"@napi-rs/canvas": "0.1.65",
|
|
"@nestjs/common": "11.0.3",
|
|
"@nestjs/core": "11.0.3",
|
|
"@prisma/client": "5.8.0",
|
|
"@remix-run/node": "2.16.8",
|
|
"@remix-run/react": "2.10.3",
|
|
"@remix-run/serve": "2.10.3",
|
|
"@resvg/resvg-js": "2.4.1",
|
|
"@swc/core": "1.3.38",
|
|
"@testing-library/jest-dom": "6.6.3",
|
|
"@testing-library/react": "16.1.0",
|
|
"@verdaccio/config": "6.0.0-6-next.76",
|
|
"acorn": "8.15.0",
|
|
"ansi-regex": "6.1.0",
|
|
"astro": "5.5.5",
|
|
"aws-cdk-lib": "2.148.0",
|
|
"axios": "1.6.8",
|
|
"body-parser": "1.20.2",
|
|
"bun-plugin-svelte": "file:../packages/bun-plugin-svelte",
|
|
"bun-plugin-yaml": "0.0.1",
|
|
"comlink": "4.4.1",
|
|
"commander": "12.1.0",
|
|
"detect-libc": "2.0.3",
|
|
"devalue": "5.1.1",
|
|
"duckdb": "1.3.1",
|
|
"es-module-lexer": "1.3.0",
|
|
"esbuild": "0.18.6",
|
|
"express": "4.18.2",
|
|
"fast-glob": "3.3.1",
|
|
"fastify": "5.2.2",
|
|
"filenamify": "6.0.0",
|
|
"happy-dom": "17.0.3",
|
|
"hono": "4.7.2",
|
|
"http2-wrapper": "2.2.1",
|
|
"https-proxy-agent": "7.0.6",
|
|
"iconv-lite": "0.6.3",
|
|
"immutable": "5.1.3",
|
|
"isbot": "5.1.13",
|
|
"jest-extended": "4.0.0",
|
|
"jimp": "1.6.0",
|
|
"jsdom": "25.0.1",
|
|
"jsonwebtoken": "9.0.2",
|
|
"jws": "4.0.0",
|
|
"lodash": "4.17.21",
|
|
"mongodb": "6.0.0",
|
|
"msgpackr-extract": "3.0.2",
|
|
"msw": "2.3.0",
|
|
"mysql2": "3.7.0",
|
|
"node-gyp": "10.0.1",
|
|
"nodemailer": "6.9.3",
|
|
"p-queue": "8.1.0",
|
|
"peechy": "0.4.310",
|
|
"pg": "8.11.1",
|
|
"pg-connection-string": "2.6.1",
|
|
"pg-gateway": "0.3.0-beta.4",
|
|
"pino": "9.4.0",
|
|
"pino-pretty": "11.2.2",
|
|
"postgres": "3.3.5",
|
|
"prisma": "5.1.1",
|
|
"prompts": "2.4.2",
|
|
"proxy": "2.2.0",
|
|
"react": "file:../node_modules/react",
|
|
"react-dom": "18.3.1",
|
|
"reflect-metadata": "0.2.2",
|
|
"rollup": "4.4.1",
|
|
"sass": "1.79.4",
|
|
"sharp": "0.33.0",
|
|
"sinon": "6.0.0",
|
|
"socket.io": "4.7.1",
|
|
"socket.io-adapter": "2.5.5",
|
|
"socket.io-client": "4.7.1",
|
|
"solc": "0.8.28",
|
|
"source-map": "0.7.4",
|
|
"st": "3.0.0",
|
|
"string-width": "7.0.0",
|
|
"strip-ansi": "7.1.0",
|
|
"stripe": "15.4.0",
|
|
"superagent": "10.2.2",
|
|
"supertest": "6.3.3",
|
|
"svelte": "5.20.4",
|
|
"tsyringe": "4.8.0",
|
|
"type-graphql": "2.0.0-rc.2",
|
|
"typeorm": "0.3.20",
|
|
"typescript": "5.9.2",
|
|
"undici": "5.20.0",
|
|
"unzipper": "0.12.3",
|
|
"uuid": "11.1.0",
|
|
"v8-heapsnapshot": "1.3.1",
|
|
"verdaccio": "6.0.0",
|
|
"vitest": "0.32.2",
|
|
"webpack": "5.88.0",
|
|
"webpack-cli": "4.7.2",
|
|
"ws": "8.18.3",
|
|
"xml2js": "0.6.2",
|
|
"yargs": "17.7.2"
|
|
},
|
|
"private": true,
|
|
"scripts": {
|
|
"typecheck": "tsc --noEmit",
|
|
"bd:v": "(bun run --silent --cwd=../ build:debug &> /tmp/bun.debug.build.log || (cat /tmp/bun.debug.build.log && rm -rf /tmp/bun.debug.build.log && exit 1)) && rm -f /tmp/bun.debug.build.log && ../build/debug/bun-debug",
|
|
"bd": "BUN_DEBUG_QUIET_LOGS=1 bun --silent bd:v"
|
|
},
|
|
"resolutions": {
|
|
"react": "../node_modules/react",
|
|
"@types/node": "25.0.0"
|
|
}
|
|
}
|