From 18529c4ef0530f0f849fb706f75a316b1290ffea Mon Sep 17 00:00:00 2001 From: eggplantzzz Date: Wed, 5 Dec 2018 18:51:29 -0500 Subject: [PATCH 1/2] Allow keepAlive option when instantiating HttpProvider --- packages/web3-providers-http/src/index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/web3-providers-http/src/index.js b/packages/web3-providers-http/src/index.js index 8a4ec985a34..fbfeba35a20 100644 --- a/packages/web3-providers-http/src/index.js +++ b/packages/web3-providers-http/src/index.js @@ -31,13 +31,16 @@ var https = require('https'); /** * HttpProvider should be used to send rpc calls over http */ -var HttpProvider = function HttpProvider(host, options) { - options = options || {}; +var HttpProvider = function HttpProvider(host, options = {}) { + const keepAlive = + (options.keepAlive === true || options.keepAlive !== false) ? + true : + false; this.host = host || 'http://localhost:8545'; - if (this.host.substring(0,5) === "https"){ - this.httpsAgent = new https.Agent({ keepAlive: true }); + if (this.host.substring(0,5) === "https") { + this.httpsAgent = new https.Agent({ keepAlive }); }else{ - this.httpAgent = new http.Agent({ keepAlive: true }); + this.httpAgent = new http.Agent({ keepAlive }); } this.timeout = options.timeout || 0; this.headers = options.headers; From 1c93c0dbaaf222631ac997946f2eb981330451d0 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Fri, 7 Dec 2018 23:03:26 -0500 Subject: [PATCH 2/2] Fix syntax for Node v5 --- packages/web3-providers-http/src/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/web3-providers-http/src/index.js b/packages/web3-providers-http/src/index.js index fbfeba35a20..f4cca379b03 100644 --- a/packages/web3-providers-http/src/index.js +++ b/packages/web3-providers-http/src/index.js @@ -31,16 +31,18 @@ var https = require('https'); /** * HttpProvider should be used to send rpc calls over http */ -var HttpProvider = function HttpProvider(host, options = {}) { - const keepAlive = +var HttpProvider = function HttpProvider(host, options) { + options = options || {}; + + var keepAlive = (options.keepAlive === true || options.keepAlive !== false) ? true : false; this.host = host || 'http://localhost:8545'; if (this.host.substring(0,5) === "https") { - this.httpsAgent = new https.Agent({ keepAlive }); + this.httpsAgent = new https.Agent({ keepAlive: keepAlive }); }else{ - this.httpAgent = new http.Agent({ keepAlive }); + this.httpAgent = new http.Agent({ keepAlive: keepAlive }); } this.timeout = options.timeout || 0; this.headers = options.headers;