mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Whitespace fixes
This commit is contained in:
parent
a088efdb04
commit
e9fd3f43d7
@ -23,26 +23,26 @@ var RoutingProxy = exports.RoutingProxy = function (options) {
|
||||
|
||||
var self = this;
|
||||
options = options || {};
|
||||
|
||||
|
||||
if (options.router) {
|
||||
this.proxyTable = new ProxyTable(options);
|
||||
this.proxyTable.on('routes', function (routes) {
|
||||
self.emit('routes', routes);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Create a set of `HttpProxy` objects to be used later on calls
|
||||
// Create a set of `HttpProxy` objects to be used later on calls
|
||||
// to `.proxyRequest()` and `.proxyWebSocketRequest()`.
|
||||
//
|
||||
this.proxies = {};
|
||||
|
||||
|
||||
//
|
||||
// Setup default target options (such as `https`).
|
||||
//
|
||||
this.target = {};
|
||||
this.target.https = options.target && options.target.https;
|
||||
|
||||
|
||||
//
|
||||
// Setup other default options to be used for instances of
|
||||
// `HttpProxy` created by this `RoutingProxy` instance.
|
||||
@ -68,27 +68,27 @@ util.inherits(RoutingProxy, events.EventEmitter);
|
||||
RoutingProxy.prototype.add = function (options) {
|
||||
var self = this,
|
||||
key = this._getKey(options);
|
||||
|
||||
|
||||
//
|
||||
// TODO: Consume properties in `options` related to the `ProxyTable`.
|
||||
//
|
||||
options.target = options.target || {};
|
||||
options.target.host = options.target.host || options.host;
|
||||
options.target.port = options.target.port || options.port;
|
||||
options.target.https = this.target && this.target.https ||
|
||||
options.target && options.target.https ||
|
||||
options.target.https = this.target && this.target.https ||
|
||||
options.target && options.target.https ||
|
||||
options.https;
|
||||
|
||||
|
||||
//
|
||||
// Setup options to pass-thru to the new `HttpProxy` instance
|
||||
// for the specified `options.host` and `options.port` pair.
|
||||
// for the specified `options.host` and `options.port` pair.
|
||||
//
|
||||
['https', 'enable', 'forward'].forEach(function (key) {
|
||||
if (options[key] !== false && self[key]) {
|
||||
options[key] = self[key];
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this.proxies[key] = new HttpProxy(options);
|
||||
this.proxies[key].on('proxyError', this.emit.bind(this, 'proxyError'));
|
||||
this.proxies[key].on('webSocketProxyError', this.emit.bind(this, 'webSocketProxyError'));
|
||||
@ -111,18 +111,18 @@ RoutingProxy.prototype.remove = function (options) {
|
||||
//
|
||||
RoutingProxy.prototype.close = function () {
|
||||
var self = this;
|
||||
|
||||
|
||||
if (this.proxyTable) {
|
||||
//
|
||||
// Close the `RoutingTable` associated with
|
||||
// Close the `RoutingTable` associated with
|
||||
// this instance (if any).
|
||||
//
|
||||
this.proxyTable.close();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Close all sockets for all `HttpProxy` object(s)
|
||||
// associated with this instance.
|
||||
// associated with this instance.
|
||||
//
|
||||
Object.keys(this.proxies).forEach(function (key) {
|
||||
self.proxies[key].close();
|
||||
@ -160,11 +160,11 @@ RoutingProxy.prototype.proxyRequest = function (req, res, options) {
|
||||
try {
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
}
|
||||
}
|
||||
catch (er) {
|
||||
console.error("res.writeHead/res.end error: %s", er.message);
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -179,15 +179,15 @@ RoutingProxy.prototype.proxyRequest = function (req, res, options) {
|
||||
options.port = location.port;
|
||||
options.host = location.host;
|
||||
}
|
||||
|
||||
|
||||
var key = this._getKey(options),
|
||||
proxy;
|
||||
|
||||
|
||||
if (!this.proxies[key]) {
|
||||
this.add(options);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
proxy = this.proxies[key];
|
||||
proxy.proxyRequest(req, res, options.buffer);
|
||||
};
|
||||
@ -206,7 +206,7 @@ RoutingProxy.prototype.proxyRequest = function (req, res, options) {
|
||||
//
|
||||
RoutingProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options) {
|
||||
options = options || {};
|
||||
|
||||
|
||||
if (this.proxyTable && !options.host) {
|
||||
location = this.proxyTable.getProxyLocation(req);
|
||||
|
||||
@ -217,7 +217,7 @@ RoutingProxy.prototype.proxyWebSocketRequest = function (req, socket, head, opti
|
||||
options.port = location.port;
|
||||
options.host = location.host;
|
||||
}
|
||||
|
||||
|
||||
var key = this._getKey(options),
|
||||
proxy;
|
||||
|
||||
@ -225,7 +225,7 @@ RoutingProxy.prototype.proxyWebSocketRequest = function (req, socket, head, opti
|
||||
this.add(options);
|
||||
}
|
||||
|
||||
proxy = this.proxies[key];
|
||||
proxy = this.proxies[key];
|
||||
proxy.proxyWebSocketRequest(req, socket, head, options.buffer);
|
||||
};
|
||||
|
||||
@ -237,14 +237,14 @@ RoutingProxy.prototype.proxyWebSocketRequest = function (req, socket, head, opti
|
||||
// combination contained within.
|
||||
//
|
||||
RoutingProxy.prototype._getKey = function (options) {
|
||||
if (!options || ((!options.host || !options.port)
|
||||
if (!options || ((!options.host || !options.port)
|
||||
&& (!options.target || !options.target.host || !options.target.port))) {
|
||||
throw new Error('options.host and options.port or options.target are required.');
|
||||
return;
|
||||
}
|
||||
|
||||
return [
|
||||
options.host || options.target.host,
|
||||
options.host || options.target.host,
|
||||
options.port || options.target.port
|
||||
].join(':');
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user