Skip to content

Commit

Permalink
[fix] remove trailing whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
yawnt committed Sep 25, 2013
1 parent 94ec6fa commit 0aeaba7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
10 changes: 5 additions & 5 deletions lib/caronte.js
Expand Up @@ -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
*/
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions lib/caronte/common.js
Expand Up @@ -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:
Expand All @@ -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]; }
);
Expand All @@ -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;

Expand Down
28 changes: 14 additions & 14 deletions lib/caronte/index.js
Expand Up @@ -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:
Expand All @@ -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];
Expand All @@ -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) {
Expand All @@ -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');
};
};
};
}

30 changes: 15 additions & 15 deletions lib/caronte/passes/web-incoming.js
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -112,40 +112,40 @@ 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();
}

] // <--
.forEach(function(func) {
passes[func.name] = func;
passes[func.name] = func;
});
12 changes: 6 additions & 6 deletions lib/caronte/passes/web-outgoing.js
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -81,5 +81,5 @@ var passes = exports;

] // <--
.forEach(function(func) {
passes[func.name] = func;
passes[func.name] = func;
});

0 comments on commit 0aeaba7

Please sign in to comment.