fix: Fix the request options for different keepAlive values
MODIFY
lib/jsonwp-proxy/proxy.js
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 {

fix: Fix the request options for different keepAlive values (#367)