mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add keepalive option in JsonApi.getResponse (#4374)
* add keepalive option in JsonApi.getResponse Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
4121672838
commit
fe4a56ba59
@ -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<RequestInit>;
|
||||
}
|
||||
|
||||
const httpAgent = new HttpAgent({ keepAlive: true });
|
||||
const httpsAgent = new HttpsAgent({ keepAlive: true });
|
||||
|
||||
export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
||||
static reqInitDefault: RequestInit = {
|
||||
headers: {
|
||||
@ -95,6 +101,10 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
||||
reqInit.method = "get";
|
||||
}
|
||||
|
||||
if (!reqInit.agent) {
|
||||
reqInit.agent = reqUrl.startsWith("https:") ? httpsAgent : httpAgent;
|
||||
}
|
||||
|
||||
if (query) {
|
||||
const queryString = stringify(query);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user