Skip to content

Commit

Permalink
Reuse Agent across requests
Browse files Browse the repository at this point in the history
  • Loading branch information
gjsjohnmurray committed Sep 18, 2024
1 parent aacb9fc commit 8de2f80
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface ConnectionSettings {

export class AtelierAPI {
private _config: ConnectionSettings;
private _agent?: httpModule.Agent | httpsModule.Agent;
private namespace: string;
public configName: string;

Expand Down Expand Up @@ -303,11 +304,13 @@ export class AtelierAPI {

const proto = this._config.https ? "https" : "http";
const http = this._config.https ? httpsModule : httpModule;
const agent = new http.Agent({
keepAlive: true,
maxSockets: 10,
rejectUnauthorized: https && vscode.workspace.getConfiguration("http").get("proxyStrictSSL"),
});
if (!this._agent) {
this._agent = new http.Agent({
keepAlive: true,
maxSockets: 10,
rejectUnauthorized: https && vscode.workspace.getConfiguration("http").get("proxyStrictSSL"),
});
}

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

0 comments on commit 8de2f80

Please sign in to comment.