diff --git a/lib/install.js b/lib/install.js index 99f6d8592a..546c8e1b86 100644 --- a/lib/install.js +++ b/lib/install.js @@ -9,7 +9,9 @@ const stream = require('stream') const crypto = require('crypto') const log = require('npmlog') const semver = require('semver') -const fetch = require('make-fetch-happen') +const got = require('got') +const HttpProxyAgent = require('https-proxy-agent') +const HttpsProxyAgent = require('https-proxy-agent') const processRelease = require('./process-release') const win = process.platform === 'win32' const streamPipeline = util.promisify(stream.pipeline) @@ -149,8 +151,8 @@ async function install (fs, gyp, argv) { try { const res = await download(gyp, release.tarballUrl) - if (res.status !== 200) { - throw new Error(`${res.status} response downloading ${release.tarballUrl}`) + if (res.statusCode !== 200) { + throw new Error(`${res.statusCode} response downloading ${release.tarballUrl}`) } await streamPipeline( @@ -214,7 +216,7 @@ async function install (fs, gyp, argv) { throw new Error(`${res.status} status code downloading checksum`) } - for (const line of (await res.text()).trim().split('\n')) { + for (const line of (await res.body).trim().split('\n')) { const items = line.trim().split(/\s+/) if (items.length !== 2) { return @@ -337,23 +339,30 @@ class ShaSum extends stream.Transform { async function download (gyp, url) { log.http('GET', url) + const cafile = gyp.opts.cafile + const requestOpts = { headers: { 'User-Agent': `node-gyp v${gyp.version} (node ${process.version})`, Connection: 'keep-alive' }, - proxy: gyp.opts.proxy, - noProxy: gyp.opts.noproxy - } - - const cafile = gyp.opts.cafile - if (cafile) { - requestOpts.ca = await readCAFile(cafile) + agent: gyp.opts.proxy + ? { + https: new HttpsProxyAgent(gyp.opts.proxy), + http: new HttpProxyAgent(gyp.opts.proxy) + } : {}, + https: cafile + ? { + certificateAuthority: await readCAFile(cafile) + } : {} } - const res = await fetch(url, requestOpts) + const res = await got(url, requestOpts) log.http(res.status, res.url) + // this is here to retain API-compatibility during v9 + // TODO: remove for v10 release + res.text = () => res.body return res } diff --git a/package.json b/package.json index 11b10b69f0..bff9efc2b3 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,10 @@ "dependencies": { "env-paths": "^2.2.0", "glob": "^7.1.4", + "got": "^11.8.6", "graceful-fs": "^4.2.6", - "make-fetch-happen": "^11.0.3", + "http-proxy-agent": "^5.0.0", + "https-proxy-agent": "^5.0.1", "nopt": "^6.0.0", "npmlog": "^6.0.0", "rimraf": "^3.0.2",