From 9fc070aceb4c449448d18229dc7767d688105266 Mon Sep 17 00:00:00 2001 From: Lionel Debroux Date: Mon, 17 Aug 2015 14:21:09 +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..fdd46a1 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.agent || 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 custom HTTPS agent used for reaching the OVH servers + * + * @param {Object} httpsAgent: the custom HTTPS agent + */ + Ovh.prototype.setCustomHTTPSAgent = function (httpsAgent) { + if (typeof(httpsAgent) === 'undefined' || typeof(httpsAgent) === 'object') { + this.httpsAgent = httpsAgent; + } + } + module.exports = function (params) { return new Ovh(params || {}); };