Skip to content

Commit

Permalink
chore: reuse proxy agent connection for all fetch requests
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Sep 5, 2023
1 parent ea092ee commit ce9066c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ const parsePackageJson = (packageJson) => {
return { binPath, url };
};

const fetchAndParseCheckSumFile = async (packageJson) => {
const fetchAndParseCheckSumFile = async (packageJson, agent) => {
const version = packageJson.version;
const pkgName = packageJson.name;
const repo = packageJson.repository;
const checksumFileUrl = `https://github.com/${repo}/releases/download/v${version}/${pkgName}_${version}_checksums.txt`;

// Fetch the checksum file
console.info("Downloading", checksumFileUrl);
const response = await fetch(checksumFileUrl, {agent: new ProxyAgent()});
const response = await fetch(checksumFileUrl, { agent });
if (response.ok) {
const checkSumContent = await response.text();
const lines = checkSumContent.split("\n");
Expand Down Expand Up @@ -124,11 +124,12 @@ async function main() {
const untar = tar.x({ cwd: binDir }, [binName]);

console.info("Downloading", url);
const resp = await fetch(url, {agent: new ProxyAgent()});
const agent = new ProxyAgent();
const resp = await fetch(url, { agent });

const hash = createHash("sha256");
const pkgNameWithPlatform = `${pkg.name}_${platform}_${arch}.tar.gz`;
const checksumMap = await fetchAndParseCheckSumFile(pkg);
const checksumMap = await fetchAndParseCheckSumFile(pkg, agent);

resp.body
.on("data", (chunk) => {
Expand Down

0 comments on commit ce9066c

Please sign in to comment.