-
Notifications
You must be signed in to change notification settings - Fork 2k
Support for HTTP CONNECT? #230
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
Comments
I don't know too much about HTTP CONNECT requests, but it looks like you can do this. You just need to change the method to a GET request when forwarding it to the target server. Here's a (basic) example: var httpProxy = require('http-proxy');
httpProxy.createServer(function (req, res, proxy) {
if (req.method === "CONNECT") req.method = "GET";
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 443
});
}).listen(80); (You can add your proxy's SSL certificate to the createServer function, see the documentation.) From what I can see, an HTTP CONNECT request can be used with any type of TCP/IP tunnel, but node-http-proxy should only be used to proxy to another HTTP(S) server. |
Thanks - I'll try that, it looks closer to the mark than what I was trying. The proxy shouldn't need an SSL cert - it should establish a connection to the remote server and port, and then from that point on it's just a plain network proxy, forwarding data back and forth. Not really HTTP at all, or as you say, just a generic TCP tunnel. It's what a browser would send if it were connecting to an SSL site through a proxy - like in a corporate environment. I'm trying to write a proxy server that can handle both - so maybe the trick is to look for that CONNECT method, and if so set up a tunnel under a different code path, and use node-http-proxy for regular HTTP. Thanks for your help. |
The proxy's SSL certificate would be for the client connecting to the proxy, not for the proxy connecting to the server. If you just wanted it to be HTTP between the client and the proxy, then you wouldn't need an SSL certificate. I mean, if you just want to proxy TCP sockets (like the net module), that's beyond the scope of node-http-proxy at this point - it's just an HTTP proxy. But as you said, you should probably set up a tunnel using a different code path, and just use node-http-proxy for the HTTP stuff. |
Just wanted to update this with some working code: It uses node-http-proxy for regular HTTP and sets up a tunnel for CONNECT requests. This works well, although there are some occasional ETIMEDOUT errors (which I'm not sure is the fault of the proxy, or if they would have timed out anyway). Thanks for the help, very nice project you've made here. |
cool! Interesting that it send an upgrade event for CONNECT requests, although I guess it makes sense. |
Yes, that was the key - I found that in the http module source code. It looks like 'connect' should work too, but it didn't for me. |
@Mogrify: This was really helpful. Thank you! I guess the connect module changed because now the 'connect' event works but 'upgrade' does not. |
Inspired by these discussion, I have create a working project. https://github.com/imhazige/node-http-connect-proxy |
@coderarity @tonygambone @regevbr @imhazige
|
@coderarity @tonygambone @regevbr @imhazige
|
I recommend using proxy-chain for such task. |
Does node-http-proxy support HTTP CONNECT requests, like:
The proxy would then maintain the two connections, and forward the SSL traffic between the client and the target server.
If so, how do I set this up?
Thanks
The text was updated successfully, but these errors were encountered: