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
proxy-agent
is not working with http proxy & web sockets
#176
Comments
Can you share your code? |
Here is a simple repro: proxy.js import * as http from 'http';
import { createProxy } from 'proxy';
const server = createProxy(http.createServer());
server.listen(3128, () => {
var port = server.address().port;
console.log('HTTP(s) proxy server listening on port %d', port);
}); server.js import { createServer } from 'node:http';
import { WebSocketServer } from 'ws';
const s = createServer((req, res) => {
console.log('request', req.url, req.headers);
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('okay');
});
s.listen(8080);
const wss = new WebSocketServer({ server: s });
wss.on('listening', () => {
console.log('Ws server listening');
});
wss.on('connection', (ws, req) => {
console.log('connected', req.url, req.headers);
}); client.js import { WebSocket } from 'ws';
import { ProxyAgent } from 'proxy-agent';
const ws1 = new WebSocket('ws://localhost:8080/ws1');
process.env['http_proxy'] = 'http://localhost:3128';
process.env['https_proxy'] = 'http://localhost:3128';
process.env['no_proxy'] = '';
const agent = new ProxyAgent();
const ws2 = new WebSocket('ws://localhost:8080/ws2', { agent }); Start In
indicates that connection without In
|
Currently a workaround is always to use import { proxies } from 'proxy-agent';
proxies['http'][0] = proxies['http'][1];
proxies['https'][0] = proxies['https'][1]; |
Fixed in |
a simple example can be found here too - https://gist.github.com/ttodua/7a66e5ca28e55deebc58b0dd8e0c39a2 |
Since proxies will drop hop-by-hop headers (
Connect
andUpgrade
), we cannot usehttp-proxy-agent
to connect to a web socket. But when I useproxy-agent
, it will sendws:
requests viahttp-proxy-agent
.The text was updated successfully, but these errors were encountered: