Skip to content

Commit

Permalink
[experiment] new api for proxying
Browse files Browse the repository at this point in the history
  • Loading branch information
yawnt committed Sep 14, 2013
1 parent 7d71a86 commit 07cfa6b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
17 changes: 15 additions & 2 deletions 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;

/*!
Expand Down Expand Up @@ -84,15 +87,25 @@ 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));
}
if(options.target) {
return req.pipe(new ProxyStream(options, res)).pipe(res);
}
res.end();
res.end();*/
}

] // <--
Expand Down
22 changes: 12 additions & 10 deletions ttest.js
Expand Up @@ -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!');
Expand All @@ -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');
Expand All @@ -33,12 +27,20 @@ client.on('open', function() {
console.log('server said: ' + msg);
});
});
*/


caronte.createProxyServer({
ws : true,
target: 'http://127.0.0.1:9090'
}).listen(8080);


/*var srv = http.createServer(function(req, res) {
res.end('1');
}).listen(8000);

var srv = http.createServer(function(req, res) {
res.end('ciao proxy');
}).listen(9090);
/*
srv.on('upgrade', function(req, sock, head) {
var options = {
Expand Down

0 comments on commit 07cfa6b

Please sign in to comment.