mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[experiment] new api for proxying
This commit is contained in:
parent
7d71a867a8
commit
07cfa6b981
@ -1,5 +1,8 @@
|
|||||||
var ForwardStream = require('../streams/forward'),
|
var ForwardStream = require('../streams/forward'),
|
||||||
ProxyStream = require('../streams/proxy'),
|
ProxyStream = require('../streams/proxy'),
|
||||||
|
http = require('http'),
|
||||||
|
https = require('https'),
|
||||||
|
common = require('../common'),
|
||||||
passes = exports;
|
passes = exports;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -84,7 +87,17 @@ function XHeaders(req, res, options) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function stream(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));
|
req.pipe(new ForwardStream(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +105,7 @@ function stream(req, res, options) {
|
|||||||
return req.pipe(new ProxyStream(options, res)).pipe(res);
|
return req.pipe(new ProxyStream(options, res)).pipe(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.end();
|
res.end();*/
|
||||||
}
|
}
|
||||||
|
|
||||||
] // <--
|
] // <--
|
||||||
|
|||||||
22
ttest.js
22
ttest.js
@ -3,7 +3,7 @@ var caronte = require('./'),
|
|||||||
http = require('http'),
|
http = require('http'),
|
||||||
ws = require('ws');
|
ws = require('ws');
|
||||||
|
|
||||||
var proxyTo = new ws.Server({ port: 9090 });
|
/*var proxyTo = new ws.Server({ port: 9090 });
|
||||||
|
|
||||||
proxyTo.on('connection', function(ws) {
|
proxyTo.on('connection', function(ws) {
|
||||||
console.log('connection!');
|
console.log('connection!');
|
||||||
@ -16,12 +16,6 @@ proxyTo.on('connection', function(ws) {
|
|||||||
ws.send('derpity?');
|
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');
|
var client = new ws('ws://127.0.0.1:8000');
|
||||||
client.on('open', function() {
|
client.on('open', function() {
|
||||||
client.send('baaaka');
|
client.send('baaaka');
|
||||||
@ -33,12 +27,20 @@ client.on('open', function() {
|
|||||||
console.log('server said: ' + msg);
|
console.log('server said: ' + msg);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*var srv = http.createServer(function(req, res) {
|
caronte.createProxyServer({
|
||||||
res.end('1');
|
ws : true,
|
||||||
}).listen(8000);
|
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) {
|
srv.on('upgrade', function(req, sock, head) {
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user