Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match node-gyp in ca and bad download handling #289

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ try {
npgVersion = JSON.parse(ownPackageJSON).version;
} catch (e) {}


// from https://github.com/nodejs/node-gyp/blob/da9cb5f41131a5e785c66073593ac515d8a8a58a/lib/install.js#L463
function readCAFile() {
// The CA file can contain multiple certificates so split on certificate
// boundaries. [\S\s]*? is used to match everything including newlines.
var ca = fs.readFileSync(filename, 'utf8')
var re = /(-----BEGIN CERTIFICATE-----[\S\s]*?-----END CERTIFICATE-----)/g
return ca.match(re)
}

function download(uri,opts,callback) {
log.http('GET', uri);

Expand All @@ -38,8 +48,9 @@ function download(uri,opts,callback) {

if (opts.cafile) {
try {
requestOpts.ca = fs.readFileSync(opts.cafile);
requestOpts.ca = readCAFile(opts.cafile);
} catch (e) {
log.error("Could not read " + opts.cafile + " (" + e.message + ")");
return callback(e);
}
} else if (opts.ca) {
Expand All @@ -61,6 +72,7 @@ function download(uri,opts,callback) {
try {
req = require('request')(requestOpts);
} catch (e) {
log.error("Could not create request " + e.message);
return callback(e);
}
if (req) {
Expand Down Expand Up @@ -105,6 +117,11 @@ function place_binary(from,to,opts,callback) {

req.on('error', function(err) {
badDownload = true;
if (err.code === 'ENOTFOUND') {
return callback(new Error('This is most likely not a problem with node-pre-gyp or the package itself and\n' +
'is related to network connectivity. In most cases you are behind a proxy or have bad \n' +
'network settings.'));
}
return callback(err);
});

Expand Down