Skip to content

Commit

Permalink
fix: add ciphers and secureProtocol params support for https request
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Mar 30, 2015
1 parent 5175866 commit 03aacb1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ httpclient.request('http://nodejs.org', function (err, body) {
- ***cert*** String | Buffer - A string or Buffer containing the certificate key of the client in PEM format.
**Notes**: This is necessary only if using the client certificate authentication
- ***passphrase*** String - A string of passphrase for the private key or pfx.
- ***ciphers*** String - A string describing the ciphers to use or exclude.
- ***secureProtocol*** String - The SSL method to use, e.g. SSLv3_method to force SSL version 3.
- ***followRedirect*** Boolean - follow HTTP 3xx responses as redirects. defaults to false.
- ***maxRedirects*** Number - The maximum number of redirects to follow, defaults to 10.
- ***beforeRequest*** Function - Before request hook, you can change every thing here.
Expand Down
23 changes: 16 additions & 7 deletions lib/urllib.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ var TEXT_DATA_TYPES = [
* - {String|Buffer} [cert]: A string or Buffer containing the certificate key of the client in PEM format.
* Notes: This is necessary only if using the client certificate authentication
* - {String} [passphrase]: A string of passphrase for the private key or pfx.
* - {String} [ciphers]: A string describing the ciphers to use or exclude.
* - {String} [secureProtocol]: The SSL method to use, e.g. SSLv3_method to force SSL version 3.
* The possible values depend on your installation of OpenSSL and are defined in the constant SSL_METHODS.
* - {Boolean} [followRedirect]: Follow HTTP 3xx responses as redirects. defaults to false.
* - {Number} [maxRedirects]: The maximum number of redirects to follow, defaults to 10.
* - {Function(options)} [beforeRequest]: Before request hook, you can change every thing here.
Expand Down Expand Up @@ -203,20 +206,26 @@ exports.requestWithCallback = function (url, args, callback) {
headers: args.headers || {}
};

var sslNames = ['ca', 'pfx', 'key', 'cert', 'passphrase'];
var sslNames = [
'pfx',
'key',
'passphrase',
'cert',
'ca',
'ciphers',
'rejectUnauthorized',
'secureProtocol',
'secureOptions',
];
for (var i = 0; i < sslNames.length; i++) {
var name = sslNames[i];
if (args[name]) {
if (args.hasOwnProperty(name)) {
options[name] = args[name];
}
}

if (args.rejectUnauthorized !== undefined) {
options.rejectUnauthorized = args.rejectUnauthorized;
}

// don't check ssl
if (options.rejectUnauthorized === false) {
if (options.rejectUnauthorized === false && !options.hasOwnProperty('secureOptions')) {
options.secureOptions = require('constants').SSL_OP_NO_TLSv1_2;
}

Expand Down

0 comments on commit 03aacb1

Please sign in to comment.