diff --git a/src/common/k8s-api/json-api.ts b/src/common/k8s-api/json-api.ts index 12bccc7a1b..5d207e13a4 100644 --- a/src/common/k8s-api/json-api.ts +++ b/src/common/k8s-api/json-api.ts @@ -21,6 +21,8 @@ // Base http-service / json-api class +import { Agent as HttpAgent } from "http"; +import { Agent as HttpsAgent } from "https"; import { merge } from "lodash"; import fetch, { Response, RequestInit } from "node-fetch"; import { stringify } from "querystring"; @@ -54,6 +56,10 @@ export interface JsonApiConfig { debug?: boolean; getRequestOptions?: () => Promise; } + +const httpAgent = new HttpAgent({ keepAlive: true }); +const httpsAgent = new HttpsAgent({ keepAlive: true }); + export class JsonApi { static reqInitDefault: RequestInit = { headers: { @@ -95,6 +101,10 @@ export class JsonApi { reqInit.method = "get"; } + if (!reqInit.agent) { + reqInit.agent = reqUrl.startsWith("https:") ? httpsAgent : httpAgent; + } + if (query) { const queryString = stringify(query);