Skip to content

Commit

Permalink
upgrade https-proxy-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Jul 8, 2024
1 parent 8edf1cc commit 6c550eb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
6 changes: 4 additions & 2 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ function place_binary(uri, targetDir, opts, callback) {
process.env.npm_config_proxy;
let agent;
if (proxyUrl) {
const ProxyAgent = require('https-proxy-agent');
agent = new ProxyAgent(proxyUrl);
// TODO: replace with undici's ProxyAgent
const { HttpsProxyAgent } = require('https-proxy-agent');
agent = new HttpsProxyAgent(proxyUrl);
log.http('download', 'proxy agent configured using: "%s"', proxyUrl);
}

// TODO: use node's built-in fetch
fetch(sanitized, { agent })
.then((res) => {
if (!res.ok) {
Expand Down
39 changes: 33 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"dependencies": {
"detect-libc": "^2.0.0",
"https-proxy-agent": "^5.0.0",
"https-proxy-agent": "^7.0.5",
"make-dir": "^3.1.0",
"node-fetch": "^2.6.7",
"nopt": "^7.2.1",
Expand Down
6 changes: 4 additions & 2 deletions test/proxy-bcrypt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { createUnzip } = require('zlib');
const os = require('os');

const tar = require('tar-fs');
const Agent = require('https-proxy-agent');
const { HttpsProxyAgent } = require('https-proxy-agent');
const fetch = require('node-fetch');
const { rimraf } = require('rimraf');

Expand Down Expand Up @@ -44,7 +44,8 @@ test('setup proxy server', (t) => {
proxy.startServer({ port: proxyPort });
process.env.https_proxy = process.env.http_proxy = proxyServer;

options.agent = new Agent(proxyServer);
// TODO: replace with undici's ProxyAgent
options.agent = new HttpsProxyAgent(proxyServer);

// make sure the download directory deleted then create an empty one
rimraf(downloadDir).then(() => {
Expand All @@ -65,6 +66,7 @@ test('verify node fetch with a proxy successfully downloads bcrypt pre-built', (
const url = 'https://github.com/kelektiv/node.bcrypt.js/releases/download/v5.0.1/bcrypt_lib-v5.0.1-napi-v3-linux-x64-glibc.tar.gz';

async function getBcrypt() {
// TODO: use node's built-in fetch
const res = await fetch(url, options);
if (res.status !== 200) {
throw new Error(`fetch got error ${res.status}`);
Expand Down

0 comments on commit 6c550eb

Please sign in to comment.