Skip to content

Commit

Permalink
Add support for using a custom HTTPS agent, through both the construc…
Browse files Browse the repository at this point in the history
…tor and a setter.

Fixes #3.

Signed-off-by: Lionel Debroux <lionel_debroux@yahoo.fr>
  • Loading branch information
debrouxl committed Aug 24, 2015
1 parent df735f7 commit cc62291
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/ovh.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var https = require('https'),
this.timeout = params.timeout;
this.apiTimeDiff = params.apiTimeDiff || null;
this.endpoint = params.endpoint || null;
this.httpsAgent = params.httpsAgent || null;

// Preconfigured API endpoints
if (this.endpoint) {
Expand Down Expand Up @@ -103,6 +104,10 @@ var https = require('https'),
path: this.basePath + path
};

if (this.httpsAgent) {
request.agent = this.httpsAgent;
}

// Fetch only selected APIs
if (path === '/') {
return async.each(
Expand Down Expand Up @@ -519,6 +524,10 @@ var https = require('https'),
'X-Ovh-Application': this.appKey,
};

if (this.httpsAgent) {
options.agent = this.httpsAgent;
}

// Remove undefined values
for (var k in params) {
if (params.hasOwnProperty(k) && typeof(params[k]) === 'undefined') {
Expand Down Expand Up @@ -654,6 +663,17 @@ var https = require('https'),
return '$1$' + crypto.createHash('sha1').update(s.join('+')).digest('hex');
};

/**
* Change the HTTPS agent used for reaching the OVH servers
*
* @param {Object} httpsAgent: the custom HTTPS agent. Pass undefined to unset a previously defined agent.
*/
Ovh.prototype.setHTTPSAgent = function (httpsAgent) {
if (typeof(httpsAgent) === 'undefined' || typeof(httpsAgent) === 'object') {
this.httpsAgent = httpsAgent;
}
};

module.exports = function (params) {
return new Ovh(params || {});
};
Expand Down

0 comments on commit cc62291

Please sign in to comment.