Skip to content

Commit

Permalink
[fix] headers, fixes #467
Browse files Browse the repository at this point in the history
  • Loading branch information
yawnt committed Sep 15, 2013
1 parent adc5be0 commit 60de543
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/caronte/index.js
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions lib/caronte/passes/web-outgoing.js
@@ -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;
});
32 changes: 22 additions & 10 deletions lib/caronte/passes/web.js
@@ -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.
*
Expand Down Expand Up @@ -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();*/
}

] // <--
Expand Down

0 comments on commit 60de543

Please sign in to comment.