diff --git a/lib/http/client.js b/lib/http/client.js index 06dce9a1..3ca7040e 100644 --- a/lib/http/client.js +++ b/lib/http/client.js @@ -197,6 +197,7 @@ HTTPClient.prototype._request = co(function* _request(method, endpoint, json) { res = yield request({ method: method, uri: this.uri + endpoint, + pool: true, query: query, json: json, auth: { diff --git a/lib/http/request.js b/lib/http/request.js index daf05995..e17fbc3c 100644 --- a/lib/http/request.js +++ b/lib/http/request.js @@ -36,6 +36,7 @@ function RequestOptions(options) { this.ssl = false; this.method = 'GET'; this.strictSSL = true; + this.pool = false; this.agent = USER_AGENT; this.type = null; @@ -106,16 +107,21 @@ RequestOptions.prototype.fromOptions = function fromOptions(options) { this.method = options.method.toUpperCase(); } - if (options.agent != null) { - assert(typeof options.agent === 'string'); - this.agent = options.agent; - } - if (options.strictSSL != null) { assert(typeof options.strictSSL === 'boolean'); this.strictSSL = options.strictSSL; } + if (options.pool != null) { + assert(typeof options.pool === 'boolean'); + this.pool = options.pool; + } + + if (options.agent != null) { + assert(typeof options.agent === 'string'); + this.agent = options.agent; + } + if (options.auth != null) { assert(typeof options.auth === 'object'); assert(typeof options.auth.username === 'string'); @@ -225,6 +231,7 @@ RequestOptions.prototype.toHTTP = function toHTTP() { port: this.port, path: this.path + query, headers: headers, + agent: this.pool ? null : false, rejectUnauthorized: this.strictSSL }; }; @@ -314,13 +321,6 @@ Request.prototype.close = function close() { } catch (e) { ; } - if (this.response.socket) { - try { - this.response.socket.destroy(); - } catch (e) { - ; - } - } } this.cleanup(); @@ -443,13 +443,6 @@ Request.prototype._onResponse = function _onResponse(response) { this.response.on('data', this.onData); this.response.on('error', this.onEnd); this.response.on('end', this.onEnd); - - if (this.response.socket) { - this.response.socket.on('error', this.onEnd); - // An agent socket's `end` sometimes - // won't be emitted on the response. - this.response.socket.on('end', this.onEnd); - } }; Request.prototype._onData = function _onData(data) { diff --git a/lib/http/rpcclient.js b/lib/http/rpcclient.js index 16fa6222..230a6ce8 100644 --- a/lib/http/rpcclient.js +++ b/lib/http/rpcclient.js @@ -48,6 +48,7 @@ RPCClient.prototype.call = co(function* call(method, params) { var res = yield request.promise({ method: 'POST', uri: this.uri, + pool: true, json: { method: method, params: params,