Skip to content

Commit 8de2f80

Browse files
committed
Reuse Agent across requests
1 parent aacb9fc commit 8de2f80

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/api/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface ConnectionSettings {
4343

4444
export class AtelierAPI {
4545
private _config: ConnectionSettings;
46+
private _agent?: httpModule.Agent | httpsModule.Agent;
4647
private namespace: string;
4748
public configName: string;
4849

@@ -303,11 +304,13 @@ export class AtelierAPI {
303304

304305
const proto = this._config.https ? "https" : "http";
305306
const http = this._config.https ? httpsModule : httpModule;
306-
const agent = new http.Agent({
307-
keepAlive: true,
308-
maxSockets: 10,
309-
rejectUnauthorized: https && vscode.workspace.getConfiguration("http").get("proxyStrictSSL"),
310-
});
307+
if (!this._agent) {
308+
this._agent = new http.Agent({
309+
keepAlive: true,
310+
maxSockets: 10,
311+
rejectUnauthorized: https && vscode.workspace.getConfiguration("http").get("proxyStrictSSL"),
312+
});
313+
}
311314

312315
let pathPrefix = this._config.pathPrefix || "";
313316
if (pathPrefix.length && !pathPrefix.startsWith("/")) {
@@ -340,7 +343,7 @@ export class AtelierAPI {
340343
const cookie = await auth;
341344
const response = await fetch(`${proto}://${host}:${port}${path}`, {
342345
method,
343-
agent,
346+
agent: this._agent,
344347
body: body ? (typeof body !== "string" ? JSON.stringify(body) : body) : null,
345348
headers: {
346349
...headers,

0 commit comments

Comments
 (0)