diff --git a/lib/jsonwp-proxy/proxy.js b/lib/jsonwp-proxy/proxy.js index bb74bf272..32d1fc48f 100644 --- a/lib/jsonwp-proxy/proxy.js +++ b/lib/jsonwp-proxy/proxy.js @@ -125,7 +125,6 @@ class JWProxy { _.isString(content) ? content : JSON.stringify(content), { length: LOG_OBJ_LENGTH }); const reqOpts = { - agent: false, url: newUrl, method, headers: { @@ -135,8 +134,18 @@ class JWProxy { }, resolveWithFullResponse: true, timeout: this.timeout, - forever: this.keepAlive, }; + if (this.keepAlive) { + reqOpts.forever = true; + // Setting `forever` option to `true` implicitly assigns + // `agent` option to `http(s).Agent({keepAlive:true})` + } else { + // Setting `agent` option to `false` prevents the requests + // module from using any connection pools, which enforces + // new socket creation for each HTTP(S) request + // (the default HTTP 1.0 behavior) + reqOpts.agent = false; + } if (util.hasValue(body)) { if (typeof body !== 'object') { try {