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

This commit is contained in:
Mykola Mokhnach
2019-11-07 18:37:17 +01:00
committed by GitHub
parent 1600980840
commit 168a01af69
+11 -2
View File
@@ -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 {