Skip to content

Commit

Permalink
Fix RoutingProxy hanging when there is an error
Browse files Browse the repository at this point in the history
  • Loading branch information
coderarity committed Mar 31, 2012
1 parent 4f2bc58 commit b26b434
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/node-http-proxy/routing-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ var RoutingProxy = exports.RoutingProxy = function (options) {
this.https = this.source.https || options.https;
this.enable = options.enable;
this.forward = options.forward;

//
// Listen for 'newListener' events so that we can bind 'proxyError'
// listeners to each HttpProxy's 'proxyError' event.
//
this.on('newListener', function (evt) {
if (evt === 'proxyError' || evt === 'webSocketProxyError') {
Object.keys(self.proxies).forEach(function (key) {
self.proxies[key].on(evt, this.emit.bind(this, evt));
});
}
});
};


Expand Down Expand Up @@ -90,8 +102,12 @@ RoutingProxy.prototype.add = function (options) {
});

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'));
if (this.listeners('proxyError').length > 0) {
this.proxies[key].on('proxyError', this.emit.bind(this, 'proxyError'));
}
if (this.listeners('webSocketProxyError').length > 0) {
this.proxies[key].on('webSocketProxyError', this.emit.bind(this, 'webSocketProxyError'));
}
this.proxies[key].on('start', this.emit.bind(this, 'start'));
this.proxies[key].on('forward', this.emit.bind(this, 'forward'));
this.proxies[key].on('end', this.emit.bind(this, 'end'));
Expand Down Expand Up @@ -188,7 +204,6 @@ RoutingProxy.prototype.proxyRequest = function (req, res, options) {

if (!this.proxies[key]) {
this.add(options);

}

proxy = this.proxies[key];
Expand Down

0 comments on commit b26b434

Please sign in to comment.