[fix] headers, fixes #467

This commit is contained in:
yawnt 2013-09-15 17:55:41 +02:00
parent adc5be020c
commit 60de543d04
3 changed files with 44 additions and 12 deletions

View File

@ -34,7 +34,7 @@ function createRightProxy(type) {
var self = this,
args = [].slice.call(arguments),
cntr = args.length - 1,
ev = 'caronte:' + type + ':',
ev = 'caronte:' + type + ':incoming:',
head;
if(
@ -53,7 +53,7 @@ function createRightProxy(type) {
passes.some(function(pass) {
var evnt = ev + pass.name.toLowerCase();
var evnt = ev + pass.name.toLowerCase() + ':';
options.ee.emit(evnt + 'begin', req, res);
var val = pass(req, res, options, head);

View File

@ -0,0 +1,20 @@
var passes = exports;
/*!
* Array of passes.
*
* A `pass` is just a function that is executed on `req, res, options`
* so that you can easily add new checks while still keeping the base
* flexible.
*/
[ // <--
function writeHeaders(res, proxyRes) {
Object.keys(proxyRes.headers).forEach(function(key) {
res.setHeader(key, proxyRes.headers[key]);
});
}
] // <--
.forEach(function(func) {
passes[func.name] = func;
});

View File

@ -1,8 +1,13 @@
var http = require('http'),
https = require('https'),
web_o = require('./web-outgoing'),
common = require('../common'),
passes = exports;
web_o = Object.keys(web_o).map(function(pass) {
return web_o[pass];
});
/*!
* Array of passes.
*
@ -100,20 +105,27 @@ function stream(req, res, options) {
req.pipe(proxyReq);
proxyReq.on('response', function(proxyRes) {
var ev = 'caronte:outgoing:web:';
options.ee.emit(ev + 'begin', req, res);
web_o.some(function(pass) {
var evnt = ev + pass.name.toLowerCase() + ':';
options.ee.emit(evnt + 'begin', req, res);
var val = pass(res, proxyRes);
options.ee.emit(evnt + 'end');
return val;
});
options.ee.emit(ev + 'end');
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();*/
}
] // <--