fix: Protocol error with http->https redirect

This commit is contained in:
Tom Moor
2026-05-30 00:12:49 -04:00
parent f6fbbcb1ad
commit 8e41344c09
+7 -1
View File
@@ -167,7 +167,13 @@ export default async function fetch(
...rest,
headers,
signal,
agent: buildAgent(url, { signal, allowPrivateIPAddress }),
// Passed as a function rather than a static agent so that node-fetch
// re-selects the correct http/https agent for each request in a redirect
// chain. Otherwise an http:// URL redirecting to https:// (or vice versa)
// would reuse the original protocol's agent and throw
// `Protocol "https:" not supported. Expected "http:"`.
agent: (parsedURL) =>
buildAgent(parsedURL.href, { signal, allowPrivateIPAddress }),
});
if (!response.ok) {