From 0990ad4a6f1d59ca9d2cb859b4e2d71693f3fc4b Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Wed, 25 Nov 2015 12:53:50 -0800 Subject: [PATCH] Fix support for proxy credentials in proxy URL and fix error when there are more than 10 outstanding requests --- src/common/connection.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/common/connection.js b/src/common/connection.js index 7836c20f..0960a3e9 100644 --- a/src/common/connection.js +++ b/src/common/connection.js @@ -15,6 +15,7 @@ function isStreamMessageType(type) { class Connection extends EventEmitter { constructor(url, options = {}) { super(); + this.setMaxListeners(Infinity); this._url = url; this._trace = options.trace; if (this._trace) { @@ -111,8 +112,10 @@ class Connection extends EventEmitter { const proxyOptions = parseURL(proxyURL); proxyOptions.secureEndpoint = (parsedURL.protocol === 'wss:'); proxyOptions.secureProxy = (proxyOptions.protocol === 'https:'); - proxyOptions.auth = proxyAuthorization; - if (trustedCertificates) { + if (proxyAuthorization !== undefined) { + proxyOptions.auth = proxyAuthorization; + } + if (trustedCertificates !== undefined) { proxyOptions.ca = trustedCertificates; } let HttpsProxyAgent; @@ -127,7 +130,11 @@ class Connection extends EventEmitter { const base64 = new Buffer(authorization).toString('base64'); options.headers = {Authorization: `Basic ${base64}`}; } - return new WebSocket(url, options); + const websocket = new WebSocket(url, options); + // we will have a listener for each outstanding request, + // so we have to raise the limit (the default is 10) + websocket.setMaxListeners(Infinity); + return websocket; } connect() {