Skip to content
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

https man in the middle #454

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

https man in the middle #454

tcurdt opened this issue Aug 23, 2013 · 3 comments

Comments

@tcurdt
Copy link

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
Copy link

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/

@cranic
Copy link

cranic commented Oct 15, 2013

Same error here..

@kalebdf
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants