Skip to content

Commit

Permalink
fix: rejectUnauthorized under Node.js 12 (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
XadillaX authored and fengmk2 committed Sep 2, 2019
1 parent 061f600 commit 3da9339
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/urllib.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var _iconv;
var pkg = require('../package.json');

var USER_AGENT = exports.USER_AGENT = ua('node-urllib', pkg.version);
var NODE_MAJOR_VERSION = parseInt(process.versions.node.split('.')[0]);

// change Agent.maxSockets to 1000
exports.agent = new http.Agent();
Expand Down Expand Up @@ -325,9 +326,11 @@ function requestWithCallback(url, args, callback) {
}
}

// don't check ssl
if (options.rejectUnauthorized === false && !options.hasOwnProperty('secureOptions')) {
options.secureOptions = require('constants').SSL_OP_NO_TLSv1_2;
// fix rejectUnauthorized when major version < 12
if (NODE_MAJOR_VERSION < 12) {
if (options.rejectUnauthorized === false && !options.hasOwnProperty('secureOptions')) {
options.secureOptions = require('constants').SSL_OP_NO_TLSv1_2;
}
}

var auth = args.auth || parsedUrl.auth;
Expand Down
2 changes: 1 addition & 1 deletion test/urllib.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ describe('test/urllib.test.js', function () {
assert(err);
assert(err.name === 'ResponseError');
err.code && assert(err.code === 'HPE_INVALID_CHUNK_SIZE');
assert(err.message.indexOf('Parse Error, GET http://127.0.0.1:') >= 0);
assert(/Parse Error.*GET http:\/\/127\.0\.0\.1:/.test(err.message) >= 0);
assert(err.bytesParsed === 2);
assert(!data);
done();
Expand Down

0 comments on commit 3da9339

Please sign in to comment.