diff --git a/lib/proxy.js b/lib/proxy.js index 84508e0..f2e951b 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -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); @@ -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(); }