From aa6e3084647d57a0103ec2b8fe5525ec980d0002 Mon Sep 17 00:00:00 2001 From: George Fu Date: Mon, 17 Jun 2024 15:45:05 +0000 Subject: [PATCH] fix(fetch-http-handler): move keepalive check to constructor (one-time) --- packages/fetch-http-handler/src/fetch-http-handler.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/fetch-http-handler/src/fetch-http-handler.ts b/packages/fetch-http-handler/src/fetch-http-handler.ts index 3d44b42ab4b..120976557fa 100644 --- a/packages/fetch-http-handler/src/fetch-http-handler.ts +++ b/packages/fetch-http-handler/src/fetch-http-handler.ts @@ -16,7 +16,7 @@ type FetchHttpHandlerConfig = FetchHttpHandlerOptions; * Detection of keepalive support. Can be overridden for testing. */ export const keepAliveSupport = { - supported: Boolean(typeof Request !== "undefined" && "keepalive" in new Request("https://[::1]")), + supported: undefined, }; /** @@ -60,6 +60,11 @@ export class FetchHttpHandler implements HttpHandler { this.config = options ?? {}; this.configProvider = Promise.resolve(this.config); } + if (keepAliveSupport.supported === undefined) { + keepAliveSupport.supported = Boolean( + typeof Request !== "undefined" && "keepalive" in new Request("https://[::1]") + ); + } } destroy(): void {