From d19b325da11c6fba1f58323a55c4b53da01d902e Mon Sep 17 00:00:00 2001 From: fry2k Date: Tue, 5 Apr 2016 16:57:28 +0200 Subject: [PATCH] try to detect proxy based on env variables --- mailgun.js | 8 +++++++- package.json | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mailgun.js b/mailgun.js index 3292d61..d5be8f4 100755 --- a/mailgun.js +++ b/mailgun.js @@ -61,7 +61,7 @@ Mailgun.prototype = {}; // Utility method to set up required http options. Mailgun.prototype._createHttpOptions = function(resource, method, servername) { - return { + var options = { host: 'api.mailgun.net', port: 443, method: method, @@ -71,6 +71,12 @@ Mailgun.prototype._createHttpOptions = function(resource, method, servername) { 'Authorization': 'Basic ' + this._apiKey64 } }; + var proxyServer = process.env.http_proxy || process.env.HTTP_PROXY || process.env.https_proxy || process.env.HTTPS_PROXY || false; + if (proxyServer !== false && proxyServer !== '') { + var HttpsProxyAgent = require('https-proxy-agent'); + options.agent = new HttpsProxyAgent(proxyServer); + } + return options; } // diff --git a/package.json b/package.json index 454fc4f..845abf4 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,9 @@ "url": "git@github.com:shz/node-mailgun.git" }, "main": "./mailgun", + "dependencies": { + "https-proxy-agent": "~1.0.0" + }, "homepage": "http://github.com/shz/node-mailgun", "engine": "node" }