Skip to content

Commit 07cfa6b

Browse files
committed
[experiment] new api for proxying
1 parent 7d71a86 commit 07cfa6b

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

lib/caronte/passes/web.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
var ForwardStream = require('../streams/forward'),
22
ProxyStream = require('../streams/proxy'),
3+
http = require('http'),
4+
https = require('https'),
5+
common = require('../common'),
36
passes = exports;
47

58
/*!
@@ -84,15 +87,25 @@ function XHeaders(req, res, options) {
8487
*/
8588

8689
function stream(req, res, options) {
87-
if(options.forward) {
90+
var proxyReq = (options.ssl ? https : http).request(
91+
common.setupOutgoing(options.ssl || {}, options, req)
92+
);
93+
94+
proxyReq.on('response', function(proxyRes) {
95+
req.pipe(proxyRes).pipe(res);
96+
});
97+
98+
proxyReq.end();
99+
100+
/*if(options.forward) {
88101
req.pipe(new ForwardStream(options));
89102
}
90103
91104
if(options.target) {
92105
return req.pipe(new ProxyStream(options, res)).pipe(res);
93106
}
94107
95-
res.end();
108+
res.end();*/
96109
}
97110

98111
] // <--

ttest.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var caronte = require('./'),
33
http = require('http'),
44
ws = require('ws');
55

6-
var proxyTo = new ws.Server({ port: 9090 });
6+
/*var proxyTo = new ws.Server({ port: 9090 });
77
88
proxyTo.on('connection', function(ws) {
99
console.log('connection!');
@@ -16,12 +16,6 @@ proxyTo.on('connection', function(ws) {
1616
ws.send('derpity?');
1717
});
1818
19-
caronte.createProxyServer({
20-
ws : true,
21-
target: 'http://127.0.0.1:9090'
22-
}).listen(8000);
23-
24-
2519
var client = new ws('ws://127.0.0.1:8000');
2620
client.on('open', function() {
2721
client.send('baaaka');
@@ -33,12 +27,20 @@ client.on('open', function() {
3327
console.log('server said: ' + msg);
3428
});
3529
});
30+
*/
31+
32+
33+
caronte.createProxyServer({
34+
ws : true,
35+
target: 'http://127.0.0.1:9090'
36+
}).listen(8080);
3637

3738

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

40+
var srv = http.createServer(function(req, res) {
41+
res.end('ciao proxy');
42+
}).listen(9090);
43+
/*
4244
srv.on('upgrade', function(req, sock, head) {
4345
4446
var options = {

0 commit comments

Comments
 (0)