http-party / node-http-proxy

A full-featured http proxy for node.js
https://github.com/http-party/node-http-proxy
Other
13.89k stars 1.97k forks source link

Is it possible to configure this to use a proxy server? #1160

Open lawred2 opened 7 years ago

lawred2 commented 7 years ago

Hi,

I have a requirement to connect to a ws endpoint. Between the clients and this endpoint is a proxy server. Is it possible to configure this http-proxy 'ws proxy' to issue connect requests to the ws endpoint through the proxy? The proxy supports CONNECT and will work with websockets.

I have tried creating a server as follows

httpProxy.createServer({
  target: 'ws://destinationbehindproxy:10231',
  forward: proxyUri,
  toProxy: true,
  ws: true
}).listen(30001);

I then issue ws client connect requests to http://localhost:30001 and I get ETIMEDOUTs

If I attempt to connect to a ws endpoint which is not behind a proxy server then all works perfectly

httpProxy.createServer({
  target: 'ws://destinationnotbehindproxy:10231',
  ws: true
}).listen(30001);

Is ws through a proxy supported? If yes, what am I doing wrong?

Regards, Dave

lawred2 commented 7 years ago

Found this related issue #832

Will try recommendations in that ticket..

richhaynes-zz commented 7 years ago

To be sure, are you trying to do the following connection using web sockets: client --> node proxy --> third party proxy --> ws server ?

If so then debugging could be hugely difficult as you have thrown a third party in the middle. If that proxy server blocks web sockets then there is nothing that can be done here. You will need to speak to the third party.

If there is the third party proxy, are you able to provide any details on what their proxy is for or what software its using etc.

lawred2 commented 7 years ago

To be sure, are you trying to do the following connection using web sockets: client --> node proxy --> third party proxy --> ws server ?

Yes. That is correct.

If so then debugging could be hugely difficult as you have thrown a third party in the middle. If that proxy server blocks web sockets then there is nothing that can be done here. You will need to speak to the third party.

Agreed. This is a corporate proxy. An absolute joy killer when it comes to development. I am working with our infra team to understand what's happening here. To aid debugging I created my own MITM relay/proxy and a ws endpoint. This ws endpoint would simply echo back any messages to the connected sender. The MITM would print out the HTTP Connect request/response interaction between client and endpoint. This works perfectly and shows that the ws connect from the client can work with a proxy that supports ws connections (HTTP CONNECT).

Now working with infra to resolve proxy issues. I think until corporate proxy issues understood we can put this ticket on hold.

-Dave

barroudjo commented 3 years ago

Use http-proxy-agent or https-proxy-agent, see #832