https man in the middle #454

Open
tcurdt opened this Issue Aug 23, 2013 · 3 comments

Comments

Projects
None yet
4 participants

tcurdt commented Aug 23, 2013

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 Oct 3, 2013

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/

@ghost

ghost commented Oct 15, 2013

Same error here..

kalebdf commented Nov 19, 2013

I believe that this is a similar error to the one happening for me and mentioned in issue #453

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment