diff --git a/lib/caronte.js b/lib/caronte.js index 337fac9..0bda8cd 100644 --- a/lib/caronte.js +++ b/lib/caronte.js @@ -7,15 +7,15 @@ var http = require('http'), /** * Creates the proxy server. - * + * * Examples: - * + * * caronte.createProxyServer({ .. }, 8000) * // => '{ web: [Function], ws: [Function] ... }' * - * @param {Object} Options Config object passed to the proxy + * @param {Object} Options Config object passed to the proxy * - * @return {Object} Proxy Proxy object with handlers for `ws` and `web` requests + * @return {Object} Proxy Proxy object with handlers for `ws` and `web` requests * * @api public */ @@ -40,7 +40,7 @@ proxy.createProxyServer = function createProxyServer(options) { ].join("\n")); } - options.ee = new events.EventEmitter2({ wildcard: true, delimiter: ':' }); + options.ee = new events.EventEmitter2({ wildcard: true, delimiter: ':' }); return { ee : options.ee, diff --git a/lib/caronte/common.js b/lib/caronte/common.js index 88a20c1..ed18aa4 100644 --- a/lib/caronte/common.js +++ b/lib/caronte/common.js @@ -2,8 +2,8 @@ var common = exports, extend = require('util')._extend; /** - * Copies the right headers from `options` and `req` to - * `outgoing` which is then used to fire the proxied + * Copies the right headers from `options` and `req` to + * `outgoing` which is then used to fire the proxied * request. * * Examples: @@ -22,9 +22,9 @@ var common = exports, */ common.setupOutgoing = function(outgoing, options, req, forward) { - outgoing.port = options[forward || 'target'].port || + outgoing.port = options[forward || 'target'].port || (~['https:', 'wss:'].indexOf(options[forward || 'target'].protocol) ? 443 : 80); - + ['host', 'hostname', 'socketPath'].forEach( function(e) { outgoing[e] = options[forward || 'target'][e]; } ); @@ -36,7 +36,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) { if (options.headers){ extend(outgoing.headers, options.headers); } - + outgoing.agent = options.agent || false; outgoing.path = req.url; diff --git a/lib/caronte/index.js b/lib/caronte/index.js index c3bb69f..214de97 100644 --- a/lib/caronte/index.js +++ b/lib/caronte/index.js @@ -8,7 +8,7 @@ caronte.createWebProxy = createRightProxy('web'); caronte.createWsProxy = createRightProxy('ws'); /** - * Returns a function that creates the loader for + * Returns a function that creates the loader for * either `ws` or `web`'s passes. * * Examples: @@ -26,7 +26,7 @@ caronte.createWsProxy = createRightProxy('ws'); function createRightProxy(type) { var passes = (type === 'ws') ? ws : web; - return function(options) { + return function(options) { passes = Object.keys(passes).map(function(pass) { return passes[pass]; @@ -42,25 +42,25 @@ function createRightProxy(type) { if( !(args[cntr] instanceof Buffer) && args[cntr] !== res - ) { + ) { //Copy global options options = extend({}, options); //Overwrite with request options extend(options, args[cntr]); - + cntr--; - } - + } + if(args[cntr] instanceof Buffer) { head = args[cntr]; } - options.ee.emit(ev + 'begin', req, res); + options.ee.emit(ev + 'begin', req, res); ['target', 'forward'].forEach( - function(e) { + function(e) { if (typeof options[e] === 'string') - options[e] = parse_url(options[e]); + options[e] = parse_url(options[e]); }); passes.some(function(pass) { @@ -74,16 +74,16 @@ function createRightProxy(type) { * refer to the connection socket * pass(req, socket, options, head) */ - - options.ee.emit(evnt + 'begin', req, res); - var val = pass(req, res, options, head); + + options.ee.emit(evnt + 'begin', req, res); + var val = pass(req, res, options, head); options.ee.emit(evnt + 'end'); - + return val; }); options.ee.emit(ev + 'end'); - }; + }; }; } diff --git a/lib/caronte/passes/web-incoming.js b/lib/caronte/passes/web-incoming.js index 1c1a6b9..eb6bbd8 100644 --- a/lib/caronte/passes/web-incoming.js +++ b/lib/caronte/passes/web-incoming.js @@ -10,7 +10,7 @@ web_o = Object.keys(web_o).map(function(pass) { /*! * 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. @@ -22,7 +22,7 @@ web_o = Object.keys(web_o).map(function(pass) { * Sets `content-length` to '0' if request is of DELETE type. * * @param {ClientRequest} Req Request object - * @param {IncomingMessage} Res Response object + * @param {IncomingMessage} Res Response object * @param {Object} Options Config object passed to the proxy * * @api private @@ -38,7 +38,7 @@ function deleteLength(req, res, options) { * Sets timeout in request socket if it was specified in options. * * @param {ClientRequest} Req Request object - * @param {IncomingMessage} Res Response object + * @param {IncomingMessage} Res Response object * @param {Object} Options Config object passed to the proxy * * @api private @@ -54,7 +54,7 @@ function timeout(req, res, options) { * Sets `x-forwarded-*` headers if specified in config. * * @param {ClientRequest} Req Request object - * @param {IncomingMessage} Res Response object + * @param {IncomingMessage} Res Response object * @param {Object} Options Config object passed to the proxy * * @api private @@ -70,7 +70,7 @@ function XHeaders(req, res, options) { }; ['for', 'port', 'proto'].forEach(function(header) { - req.headers['x-forwarded-' + header] = + req.headers['x-forwarded-' + header] = (req.headers['x-forwarded-' + header] || '') + (req.headers['x-forwarded-' + header] ? ',' : '') + values[header] @@ -83,7 +83,7 @@ function XHeaders(req, res, options) { * just dies otherwise. * * @param {ClientRequest} Req Request object - * @param {IncomingMessage} Res Response object + * @param {IncomingMessage} Res Response object * @param {Object} Options Config object passed to the proxy * * @api private @@ -112,34 +112,34 @@ function stream(req, res, options) { throw err; } // Also emit the error events - options.ee.emit(ev + 'error', err, req, res); + options.ee.emit(ev + 'error', err, req, res); }); - + req.pipe(proxyReq); proxyReq.on('response', function(proxyRes) { var ev = 'caronte:outgoing:web:'; - options.ee.emit(ev + 'begin', req, res); - + options.ee.emit(ev + 'begin', req, res); + // When the previous request respond, we apply the // outgoing passes to the response web_o.some(function(pass) { var evnt = ev + pass.name.toLowerCase() + ':'; - + options.ee.emit(evnt + 'begin', req, res); // Call the pass with the proxy response // pass(ClientRequest, IncomingMessage, proxyResponse) - var val = pass(req, res, proxyRes); + var val = pass(req, res, proxyRes); options.ee.emit(evnt + 'end'); - + return val; }); options.ee.emit(ev + 'end'); - proxyRes.pipe(res); + proxyRes.pipe(res); }); //proxyReq.end(); @@ -147,5 +147,5 @@ function stream(req, res, options) { ] // <-- .forEach(function(func) { - passes[func.name] = func; + passes[func.name] = func; }); diff --git a/lib/caronte/passes/web-outgoing.js b/lib/caronte/passes/web-outgoing.js index abdaec9..20f94fd 100644 --- a/lib/caronte/passes/web-outgoing.js +++ b/lib/caronte/passes/web-outgoing.js @@ -2,7 +2,7 @@ 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. @@ -14,7 +14,7 @@ var passes = exports; * If is a HTTP 1.0 request, remove chunk headers * * @param {ClientRequest} Req Request object - * @param {IncomingMessage} Res Response object + * @param {IncomingMessage} Res Response object * @param {proxyResponse} Res Response object from the proxy request * * @api private @@ -30,7 +30,7 @@ var passes = exports; * or if connection header not present, then use `keep-alive` * * @param {ClientRequest} Req Request object - * @param {IncomingMessage} Res Response object + * @param {IncomingMessage} Res Response object * @param {proxyResponse} Res Response object from the proxy request * * @api private @@ -55,7 +55,7 @@ var passes = exports; * set each header in response object. * * @param {ClientRequest} Req Request object - * @param {IncomingMessage} Res Response object + * @param {IncomingMessage} Res Response object * @param {proxyResponse} Res Response object from the proxy request * * @api private @@ -70,7 +70,7 @@ var passes = exports; * Set the statusCode from the proxyResponse * * @param {ClientRequest} Req Request object - * @param {IncomingMessage} Res Response object + * @param {IncomingMessage} Res Response object * @param {proxyResponse} Res Response object from the proxy request * * @api private @@ -81,5 +81,5 @@ var passes = exports; ] // <-- .forEach(function(func) { - passes[func.name] = func; + passes[func.name] = func; });