Skip to content

Commit f82566c

Browse files
sagar-routSagar Rout
authored andcommitted
Set default http agent with max cached sessions of 50
1 parent 2d1143c commit f82566c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/lambda-edge/shared/shared.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export {
1616
JwtExpiredError,
1717
} from "aws-jwt-verify/error";
1818

19+
const DEFAULT_MAX_CACHED_SESSIONS : number = 50;
20+
1921
export interface CookieSettings {
2022
idToken: string;
2123
accessToken: string;
@@ -24,6 +26,10 @@ export interface CookieSettings {
2426
[key: string]: string;
2527
}
2628

29+
function getDefaultAgent() : Agent {
30+
return new Agent({rejectUnauthorized: true, maxCachedSessions: DEFAULT_MAX_CACHED_SESSIONS});
31+
}
32+
2733
function getDefaultCookieSettings(props: {
2834
mode: "spaMode" | "staticSiteMode";
2935
compatibility: "amplify" | "elasticsearch";
@@ -503,7 +509,7 @@ export async function httpPostToCognitoWithRetry(
503509
++attempts;
504510
try {
505511
return await fetch(url, data, {
506-
agent: AGENT,
512+
agent: AGENT || getDefaultAgent(),
507513
...options,
508514
method: "POST",
509515
}).then((res) => {

0 commit comments

Comments
 (0)