mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[fix] remove trailing whitespaces
This commit is contained in:
parent
94ec6fa5ce
commit
0aeaba7fe6
@ -7,15 +7,15 @@ var http = require('http'),
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the proxy server.
|
* Creates the proxy server.
|
||||||
*
|
*
|
||||||
* Examples:
|
* Examples:
|
||||||
*
|
*
|
||||||
* caronte.createProxyServer({ .. }, 8000)
|
* caronte.createProxyServer({ .. }, 8000)
|
||||||
* // => '{ web: [Function], ws: [Function] ... }'
|
* // => '{ 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
|
* @api public
|
||||||
*/
|
*/
|
||||||
@ -40,7 +40,7 @@ proxy.createProxyServer = function createProxyServer(options) {
|
|||||||
].join("\n"));
|
].join("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
options.ee = new events.EventEmitter2({ wildcard: true, delimiter: ':' });
|
options.ee = new events.EventEmitter2({ wildcard: true, delimiter: ':' });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ee : options.ee,
|
ee : options.ee,
|
||||||
|
|||||||
@ -2,8 +2,8 @@ var common = exports,
|
|||||||
extend = require('util')._extend;
|
extend = require('util')._extend;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies the right headers from `options` and `req` to
|
* Copies the right headers from `options` and `req` to
|
||||||
* `outgoing` which is then used to fire the proxied
|
* `outgoing` which is then used to fire the proxied
|
||||||
* request.
|
* request.
|
||||||
*
|
*
|
||||||
* Examples:
|
* Examples:
|
||||||
@ -22,9 +22,9 @@ var common = exports,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
common.setupOutgoing = function(outgoing, options, req, forward) {
|
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);
|
(~['https:', 'wss:'].indexOf(options[forward || 'target'].protocol) ? 443 : 80);
|
||||||
|
|
||||||
['host', 'hostname', 'socketPath'].forEach(
|
['host', 'hostname', 'socketPath'].forEach(
|
||||||
function(e) { outgoing[e] = options[forward || 'target'][e]; }
|
function(e) { outgoing[e] = options[forward || 'target'][e]; }
|
||||||
);
|
);
|
||||||
@ -36,7 +36,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
|
|||||||
if (options.headers){
|
if (options.headers){
|
||||||
extend(outgoing.headers, options.headers);
|
extend(outgoing.headers, options.headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
outgoing.agent = options.agent || false;
|
outgoing.agent = options.agent || false;
|
||||||
outgoing.path = req.url;
|
outgoing.path = req.url;
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ caronte.createWebProxy = createRightProxy('web');
|
|||||||
caronte.createWsProxy = createRightProxy('ws');
|
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.
|
* either `ws` or `web`'s passes.
|
||||||
*
|
*
|
||||||
* Examples:
|
* Examples:
|
||||||
@ -26,7 +26,7 @@ caronte.createWsProxy = createRightProxy('ws');
|
|||||||
function createRightProxy(type) {
|
function createRightProxy(type) {
|
||||||
var passes = (type === 'ws') ? ws : web;
|
var passes = (type === 'ws') ? ws : web;
|
||||||
|
|
||||||
return function(options) {
|
return function(options) {
|
||||||
|
|
||||||
passes = Object.keys(passes).map(function(pass) {
|
passes = Object.keys(passes).map(function(pass) {
|
||||||
return passes[pass];
|
return passes[pass];
|
||||||
@ -42,25 +42,25 @@ function createRightProxy(type) {
|
|||||||
if(
|
if(
|
||||||
!(args[cntr] instanceof Buffer) &&
|
!(args[cntr] instanceof Buffer) &&
|
||||||
args[cntr] !== res
|
args[cntr] !== res
|
||||||
) {
|
) {
|
||||||
//Copy global options
|
//Copy global options
|
||||||
options = extend({}, options);
|
options = extend({}, options);
|
||||||
//Overwrite with request options
|
//Overwrite with request options
|
||||||
extend(options, args[cntr]);
|
extend(options, args[cntr]);
|
||||||
|
|
||||||
cntr--;
|
cntr--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(args[cntr] instanceof Buffer) {
|
if(args[cntr] instanceof Buffer) {
|
||||||
head = args[cntr];
|
head = args[cntr];
|
||||||
}
|
}
|
||||||
|
|
||||||
options.ee.emit(ev + 'begin', req, res);
|
options.ee.emit(ev + 'begin', req, res);
|
||||||
|
|
||||||
['target', 'forward'].forEach(
|
['target', 'forward'].forEach(
|
||||||
function(e) {
|
function(e) {
|
||||||
if (typeof options[e] === 'string')
|
if (typeof options[e] === 'string')
|
||||||
options[e] = parse_url(options[e]);
|
options[e] = parse_url(options[e]);
|
||||||
});
|
});
|
||||||
|
|
||||||
passes.some(function(pass) {
|
passes.some(function(pass) {
|
||||||
@ -74,16 +74,16 @@ function createRightProxy(type) {
|
|||||||
* refer to the connection socket
|
* refer to the connection socket
|
||||||
* pass(req, socket, options, head)
|
* pass(req, socket, options, head)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
options.ee.emit(evnt + 'begin', req, res);
|
options.ee.emit(evnt + 'begin', req, res);
|
||||||
var val = pass(req, res, options, head);
|
var val = pass(req, res, options, head);
|
||||||
options.ee.emit(evnt + 'end');
|
options.ee.emit(evnt + 'end');
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
});
|
});
|
||||||
|
|
||||||
options.ee.emit(ev + 'end');
|
options.ee.emit(ev + 'end');
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ web_o = Object.keys(web_o).map(function(pass) {
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Array of passes.
|
* Array of passes.
|
||||||
*
|
*
|
||||||
* A `pass` is just a function that is executed on `req, res, options`
|
* 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
|
* so that you can easily add new checks while still keeping the base
|
||||||
* flexible.
|
* 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.
|
* Sets `content-length` to '0' if request is of DELETE type.
|
||||||
*
|
*
|
||||||
* @param {ClientRequest} Req Request object
|
* @param {ClientRequest} Req Request object
|
||||||
* @param {IncomingMessage} Res Response object
|
* @param {IncomingMessage} Res Response object
|
||||||
* @param {Object} Options Config object passed to the proxy
|
* @param {Object} Options Config object passed to the proxy
|
||||||
*
|
*
|
||||||
* @api private
|
* @api private
|
||||||
@ -38,7 +38,7 @@ function deleteLength(req, res, options) {
|
|||||||
* Sets timeout in request socket if it was specified in options.
|
* Sets timeout in request socket if it was specified in options.
|
||||||
*
|
*
|
||||||
* @param {ClientRequest} Req Request object
|
* @param {ClientRequest} Req Request object
|
||||||
* @param {IncomingMessage} Res Response object
|
* @param {IncomingMessage} Res Response object
|
||||||
* @param {Object} Options Config object passed to the proxy
|
* @param {Object} Options Config object passed to the proxy
|
||||||
*
|
*
|
||||||
* @api private
|
* @api private
|
||||||
@ -54,7 +54,7 @@ function timeout(req, res, options) {
|
|||||||
* Sets `x-forwarded-*` headers if specified in config.
|
* Sets `x-forwarded-*` headers if specified in config.
|
||||||
*
|
*
|
||||||
* @param {ClientRequest} Req Request object
|
* @param {ClientRequest} Req Request object
|
||||||
* @param {IncomingMessage} Res Response object
|
* @param {IncomingMessage} Res Response object
|
||||||
* @param {Object} Options Config object passed to the proxy
|
* @param {Object} Options Config object passed to the proxy
|
||||||
*
|
*
|
||||||
* @api private
|
* @api private
|
||||||
@ -70,7 +70,7 @@ function XHeaders(req, res, options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
['for', 'port', 'proto'].forEach(function(header) {
|
['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] || '') +
|
||||||
(req.headers['x-forwarded-' + header] ? ',' : '') +
|
(req.headers['x-forwarded-' + header] ? ',' : '') +
|
||||||
values[header]
|
values[header]
|
||||||
@ -83,7 +83,7 @@ function XHeaders(req, res, options) {
|
|||||||
* just dies otherwise.
|
* just dies otherwise.
|
||||||
*
|
*
|
||||||
* @param {ClientRequest} Req Request object
|
* @param {ClientRequest} Req Request object
|
||||||
* @param {IncomingMessage} Res Response object
|
* @param {IncomingMessage} Res Response object
|
||||||
* @param {Object} Options Config object passed to the proxy
|
* @param {Object} Options Config object passed to the proxy
|
||||||
*
|
*
|
||||||
* @api private
|
* @api private
|
||||||
@ -112,34 +112,34 @@ function stream(req, res, options) {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// Also emit the error events
|
// Also emit the error events
|
||||||
options.ee.emit(ev + 'error', err, req, res);
|
options.ee.emit(ev + 'error', err, req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
req.pipe(proxyReq);
|
req.pipe(proxyReq);
|
||||||
|
|
||||||
proxyReq.on('response', function(proxyRes) {
|
proxyReq.on('response', function(proxyRes) {
|
||||||
var ev = 'caronte:outgoing:web:';
|
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
|
// When the previous request respond, we apply the
|
||||||
// outgoing passes to the response
|
// outgoing passes to the response
|
||||||
web_o.some(function(pass) {
|
web_o.some(function(pass) {
|
||||||
var evnt = ev + pass.name.toLowerCase() + ':';
|
var evnt = ev + pass.name.toLowerCase() + ':';
|
||||||
|
|
||||||
options.ee.emit(evnt + 'begin', req, res);
|
options.ee.emit(evnt + 'begin', req, res);
|
||||||
// Call the pass with the proxy response
|
// Call the pass with the proxy response
|
||||||
// pass(ClientRequest, IncomingMessage, proxyResponse)
|
// pass(ClientRequest, IncomingMessage, proxyResponse)
|
||||||
var val = pass(req, res, proxyRes);
|
var val = pass(req, res, proxyRes);
|
||||||
options.ee.emit(evnt + 'end');
|
options.ee.emit(evnt + 'end');
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
});
|
});
|
||||||
|
|
||||||
options.ee.emit(ev + 'end');
|
options.ee.emit(ev + 'end');
|
||||||
|
|
||||||
|
|
||||||
proxyRes.pipe(res);
|
proxyRes.pipe(res);
|
||||||
});
|
});
|
||||||
|
|
||||||
//proxyReq.end();
|
//proxyReq.end();
|
||||||
@ -147,5 +147,5 @@ function stream(req, res, options) {
|
|||||||
|
|
||||||
] // <--
|
] // <--
|
||||||
.forEach(function(func) {
|
.forEach(function(func) {
|
||||||
passes[func.name] = func;
|
passes[func.name] = func;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,7 +2,7 @@ var passes = exports;
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Array of passes.
|
* Array of passes.
|
||||||
*
|
*
|
||||||
* A `pass` is just a function that is executed on `req, res, options`
|
* 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
|
* so that you can easily add new checks while still keeping the base
|
||||||
* flexible.
|
* flexible.
|
||||||
@ -14,7 +14,7 @@ var passes = exports;
|
|||||||
* If is a HTTP 1.0 request, remove chunk headers
|
* If is a HTTP 1.0 request, remove chunk headers
|
||||||
*
|
*
|
||||||
* @param {ClientRequest} Req Request 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
|
* @param {proxyResponse} Res Response object from the proxy request
|
||||||
*
|
*
|
||||||
* @api private
|
* @api private
|
||||||
@ -30,7 +30,7 @@ var passes = exports;
|
|||||||
* or if connection header not present, then use `keep-alive`
|
* or if connection header not present, then use `keep-alive`
|
||||||
*
|
*
|
||||||
* @param {ClientRequest} Req Request 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
|
* @param {proxyResponse} Res Response object from the proxy request
|
||||||
*
|
*
|
||||||
* @api private
|
* @api private
|
||||||
@ -55,7 +55,7 @@ var passes = exports;
|
|||||||
* set each header in response object.
|
* set each header in response object.
|
||||||
*
|
*
|
||||||
* @param {ClientRequest} Req Request 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
|
* @param {proxyResponse} Res Response object from the proxy request
|
||||||
*
|
*
|
||||||
* @api private
|
* @api private
|
||||||
@ -70,7 +70,7 @@ var passes = exports;
|
|||||||
* Set the statusCode from the proxyResponse
|
* Set the statusCode from the proxyResponse
|
||||||
*
|
*
|
||||||
* @param {ClientRequest} Req Request 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
|
* @param {proxyResponse} Res Response object from the proxy request
|
||||||
*
|
*
|
||||||
* @api private
|
* @api private
|
||||||
@ -81,5 +81,5 @@ var passes = exports;
|
|||||||
|
|
||||||
] // <--
|
] // <--
|
||||||
.forEach(function(func) {
|
.forEach(function(func) {
|
||||||
passes[func.name] = func;
|
passes[func.name] = func;
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user