Skip to content

Commit 9fc070a

Browse files
committed
Add support for using a custom HTTPS agent, through both the constructor and a setter.
Fixes #3. Signed-off-by: Lionel Debroux <[email protected]>
1 parent df735f7 commit 9fc070a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/ovh.js

+20
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var https = require('https'),
4343
this.timeout = params.timeout;
4444
this.apiTimeDiff = params.apiTimeDiff || null;
4545
this.endpoint = params.endpoint || null;
46+
this.httpsAgent = params.agent || null;
4647

4748
// Preconfigured API endpoints
4849
if (this.endpoint) {
@@ -103,6 +104,10 @@ var https = require('https'),
103104
path: this.basePath + path
104105
};
105106

107+
if (this.httpsAgent) {
108+
request.agent = this.httpsAgent;
109+
}
110+
106111
// Fetch only selected APIs
107112
if (path === '/') {
108113
return async.each(
@@ -519,6 +524,10 @@ var https = require('https'),
519524
'X-Ovh-Application': this.appKey,
520525
};
521526

527+
if (this.httpsAgent) {
528+
options.agent = this.httpsAgent;
529+
}
530+
522531
// Remove undefined values
523532
for (var k in params) {
524533
if (params.hasOwnProperty(k) && typeof(params[k]) === 'undefined') {
@@ -654,6 +663,17 @@ var https = require('https'),
654663
return '$1$' + crypto.createHash('sha1').update(s.join('+')).digest('hex');
655664
};
656665

666+
/**
667+
* Change the custom HTTPS agent used for reaching the OVH servers
668+
*
669+
* @param {Object} httpsAgent: the custom HTTPS agent
670+
*/
671+
Ovh.prototype.setCustomHTTPSAgent = function (httpsAgent) {
672+
if (typeof(httpsAgent) === 'undefined' || typeof(httpsAgent) === 'object') {
673+
this.httpsAgent = httpsAgent;
674+
}
675+
}
676+
657677
module.exports = function (params) {
658678
return new Ovh(params || {});
659679
};

0 commit comments

Comments
 (0)