From cc6229147ed37a22fc81d037e159a0662facaac2 Mon Sep 17 00:00:00 2001 From: Lionel Debroux Date: Mon, 24 Aug 2015 11:15:01 +0200 Subject: [PATCH] Add support for using a custom HTTPS agent, through both the constructor and a setter. Fixes #3. Signed-off-by: Lionel Debroux --- lib/ovh.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/ovh.js b/lib/ovh.js index 03ec84f..80fd8f3 100644 --- a/lib/ovh.js +++ b/lib/ovh.js @@ -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) { @@ -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( @@ -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') { @@ -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 || {}); };