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);