diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index 6590ed9..92541ba 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -103,6 +103,9 @@ var HttpProxy = exports.HttpProxy = function (options) { ? this.enable.xforward : true; + // if event listener is set then use it else unlimited. + this.eventListenerCount = typeof options.eventListenerCount === 'number'? options.eventListenerCount : 0 ; + // // Setup additional options for WebSocket proxying. When forcing // the WebSocket handshake to change the `sec-websocket-location` @@ -371,10 +374,9 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { res.on('drain', ondrain); }); - // allow unlimited listeners ... - reverseProxy.setMaxListeners(0); - + reverseProxy.setMaxListeners(this.eventListenerCount); + // // Handle 'error' events from the `reverseProxy`. Setup timeout override if needed //