From 7e469cc27434aa70e1e21caaed107e2775e2b532 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Sun, 1 Feb 2026 23:04:32 +0000 Subject: [PATCH] fix: Reset `agent` on retry/redirect (#27) --- .changeset/slimy-boats-worry.md | 5 +++++ src/fetch.ts | 9 ++++----- 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 .changeset/slimy-boats-worry.md diff --git a/.changeset/slimy-boats-worry.md b/.changeset/slimy-boats-worry.md new file mode 100644 index 0000000..4c0c83c --- /dev/null +++ b/.changeset/slimy-boats-worry.md @@ -0,0 +1,5 @@ +--- +'fetch-nodeshim': patch +--- + +Reset `requestOptions.agent` on retry/redirect diff --git a/src/fetch.ts b/src/fetch.ts index 338b506..e2cf863 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -134,15 +134,14 @@ async function _fetch( signal, } satisfies http.RequestOptions; - requestOptions.agent = - requestOptions.protocol === 'https:' - ? getHttpsAgent(requestOptions) - : getHttpAgent(requestOptions); - function _call( resolve: (response: Response | Promise) => void, reject: (reason?: any) => void ) { + requestOptions.agent = + requestOptions.protocol === 'https:' + ? getHttpsAgent(requestOptions) + : getHttpAgent(requestOptions); const method = requestOptions.method; const protocol = requestOptions.protocol === 'https:' ? https : http; const outgoing = protocol.request(requestOptions); -- 2.51.2