Use createHTTPSAgent for all requests

This commit is contained in:
Fedor Indutny 2023-12-12 23:57:09 +01:00 committed by GitHub
parent 15e1d6e441
commit f8c4e392fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 42 deletions

View file

@ -1367,13 +1367,17 @@ export function initialize({
log.warn(`${logId}: Done`);
}
let fetchForLinkPreviews: linkPreviewFetch.FetchFn;
let fetchAgent: Agent;
if (proxyUrl) {
const agent = createProxyAgent(proxyUrl);
fetchForLinkPreviews = (href, init) => fetch(href, { ...init, agent });
fetchAgent = createProxyAgent(proxyUrl);
} else {
fetchForLinkPreviews = fetch;
fetchAgent = createHTTPSAgent({
keepAlive: false,
maxCachedSessions: 0,
});
}
const fetchForLinkPreviews: linkPreviewFetch.FetchFn = (href, init) =>
fetch(href, { ...init, agent: fetchAgent });
// Thanks, function hoisting!
return {