Skip to content

Commit

Permalink
Intercepted HTTPS
Browse files Browse the repository at this point in the history
add: intercept works on https streams now.
bug: doesn't pass everything thru. Stream seems to get cut off somehow.

Signed-off-by: Josh Erickson <josh@snoj.us>
  • Loading branch information
snoj committed Jun 26, 2015
1 parent fe08bcf commit 5fb5ff1
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions lib/proxy.js
Expand Up @@ -171,10 +171,10 @@ module.exports = Base.extend(function(opts){
//todo: defer if not listening yet?
var t = thisProxy._passthru.address();
var near = require('net').connect(t.port, t.address.replace("::", "::1").replace("0.0.0.0", "127.0.0.1"), function() {
tlsportmap[near.address().address + '-' + near.address().port] = hinfo;
socket.write('HTTP/1.1 200 Connection Established\r\n' +
'Proxy-agent: node-hoxy-proxy\r\n' +
'\r\n');
tlsportmap[near.address().address + '-' + near.address().port] = hinfo;
near.write(head);
near.pipe(socket);
socket.pipe(near);
Expand All @@ -195,15 +195,8 @@ module.exports = Base.extend(function(opts){
thisProxy._passthru = https.createServer(opts.tlspassthru, function(req, res) {
var hinfo = tlsportmap[req.socket.remoteAddress + '-' + req.socket.remotePort];

var realreqopts = require('url').parse('https://' + req.headers.host + req.url);
realreqopts.port = hinfo.port;
realreqopts.method = req.method;
realreqopts.rejectUnauthorized = false;

var realreq = https.request(realreqopts, function(realres) {
realres.pipe(res);
});
req.pipe(realreq);
req.url = 'https://' + req.headers.host + ':' + hinfo.port + req.url;
handler(req, res);
});
thisProxy._passthru.listen();
}
Expand Down

0 comments on commit 5fb5ff1

Please sign in to comment.