http-party / node-http-proxy

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

https man in the middle #454

Open tcurdt opened 10 years ago

tcurdt commented 10 years ago

I am trying to log http and https traffic going through the proxy. After a little fiddling around I came up with the following code. Unfortunately it does not work for https and I am not sure why not.

var url = require('url'),
    fs = require('fs'),
    http = require('http'),
    httpProxy = require('http-proxy');

var httpOptions = {
};

var httpsOptions = {
    https: {
      passphrase: 'test',
      key: fs.readFileSync('certs/key.pem', 'utf8'),
      cert: fs.readFileSync('certs/cert.pem', 'utf8')
    },
    target: {
      https: true
    }
};

httpProxy.createServer(httpOptions, function (req, res, proxy) {
  console.log('- ' + req.url);
  var u = url.parse(req.url);
  proxy.proxyRequest(req, res, { port: u.port ? u.port : 80, host: u.hostname });
}).listen(8000);

httpProxy.createServer(httpsOptions, function (req, res, proxy) {
  console.log('+ ' + req.url);
  var u = url.parse(req.url);
  proxy.proxyRequest(req, res, { port: u.port ? u.port : 443, host: u.hostname });
}).listen(8001);

console.log('listening...');

Testing with curl

export http_proxy=http://localhost:8000
export https_proxy=http://localhost:8001
curl http://vafer.org
curl https://google.com

For https it just sits there and nothing happens. But I am not even getting a callback in the server.

Bug? Wrong expectations? What am I missing?

gisripa commented 10 years ago

I am trying to achieve the same thing and apparently ended up writing my own proxy for https. From the http-proxy code I see there is no callback registered for "CONNECT" event.

The following blog helped. http://newspaint.wordpress.com/2012/11/05/node-js-http-and-https-proxy/

cranic commented 10 years ago

Same error here..

kalebdf commented 10 years ago

I believe that this is a similar error to the one happening for me and mentioned in issue https://github.com/nodejitsu/node-http-proxy/issues/453