diff --git a/lib/caronte/passes/web.js b/lib/caronte/passes/web.js index dc815ab..363d8ff 100644 --- a/lib/caronte/passes/web.js +++ b/lib/caronte/passes/web.js @@ -1,5 +1,8 @@ var ForwardStream = require('../streams/forward'), ProxyStream = require('../streams/proxy'), + http = require('http'), + https = require('https'), + common = require('../common'), passes = exports; /*! @@ -84,7 +87,17 @@ function XHeaders(req, res, options) { */ function stream(req, res, options) { - if(options.forward) { + var proxyReq = (options.ssl ? https : http).request( + common.setupOutgoing(options.ssl || {}, options, req) + ); + + proxyReq.on('response', function(proxyRes) { + req.pipe(proxyRes).pipe(res); + }); + + proxyReq.end(); + + /*if(options.forward) { req.pipe(new ForwardStream(options)); } @@ -92,7 +105,7 @@ function stream(req, res, options) { return req.pipe(new ProxyStream(options, res)).pipe(res); } - res.end(); + res.end();*/ } ] // <-- diff --git a/ttest.js b/ttest.js index ee34ed6..2101db6 100644 --- a/ttest.js +++ b/ttest.js @@ -3,7 +3,7 @@ var caronte = require('./'), http = require('http'), ws = require('ws'); -var proxyTo = new ws.Server({ port: 9090 }); +/*var proxyTo = new ws.Server({ port: 9090 }); proxyTo.on('connection', function(ws) { console.log('connection!'); @@ -16,12 +16,6 @@ proxyTo.on('connection', function(ws) { ws.send('derpity?'); }); -caronte.createProxyServer({ - ws : true, - target: 'http://127.0.0.1:9090' -}).listen(8000); - - var client = new ws('ws://127.0.0.1:8000'); client.on('open', function() { client.send('baaaka'); @@ -33,12 +27,20 @@ client.on('open', function() { console.log('server said: ' + msg); }); }); +*/ -/*var srv = http.createServer(function(req, res) { - res.end('1'); -}).listen(8000); +caronte.createProxyServer({ + ws : true, + target: 'http://127.0.0.1:9090' +}).listen(8080); + + +var srv = http.createServer(function(req, res) { + res.end('ciao proxy'); +}).listen(9090); +/* srv.on('upgrade', function(req, sock, head) { var options = {