1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

add keepalive option in JsonApi.getResponse

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2021-11-17 18:13:27 +02:00
parent 2446b6cf9b
commit 9aa5b5d875

View File

@ -21,6 +21,8 @@
// Base http-service / json-api class // Base http-service / json-api class
import { Agent as HttpAgent } from "http";
import { Agent as HttpsAgent } from "https";
import { merge } from "lodash"; import { merge } from "lodash";
import fetch, { Response, RequestInit } from "node-fetch"; import fetch, { Response, RequestInit } from "node-fetch";
import { stringify } from "querystring"; import { stringify } from "querystring";
@ -95,6 +97,12 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
reqInit.method = "get"; reqInit.method = "get";
} }
if (!reqInit.agent) {
const agentOpts = { keepAlive: true };
reqInit.agent = reqUrl.startsWith("https:") ? new HttpsAgent(agentOpts) : new HttpAgent(agentOpts);
}
if (query) { if (query) {
const queryString = stringify(query); const queryString = stringify(query);