diff --git a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js index 4945c5c8b..6f682b279 100644 --- a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js +++ b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js @@ -111,9 +111,13 @@ module.exports = function(RED) { if (typeof this.cleansession === 'undefined') { this.cleansession = true; } - var prox; - if (process.env.http_proxy != null) { prox = process.env.http_proxy; } - if (process.env.HTTP_PROXY != null) { prox = process.env.HTTP_PROXY; } + + var prox, noprox; + if (process.env.http_proxy) { prox = process.env.http_proxy; } + if (process.env.HTTP_PROXY) { prox = process.env.HTTP_PROXY; } + if (process.env.no_proxy) { noprox = process.env.no_proxy.split(","); } + if (process.env.NO_PROXY) { noprox = process.env.NO_PROXY.split(","); } + // Create the URL to pass in to the MQTT.js library if (this.brokerurl === "") { @@ -121,9 +125,15 @@ module.exports = function(RED) { if (this.broker.indexOf("://") > -1) { this.brokerurl = this.broker; // Only for ws or wss, check if proxy env var for additional configuration - if (this.brokerurl.indexOf("wss://") > -1 || this.brokerurl.indexOf("ws://") > -1 ) - // check if proxy is set in env - if (prox) { + if (this.brokerurl.indexOf("wss://") > -1 || this.brokerurl.indexOf("ws://") > -1 ) { + // check if proxy is set in env + var noproxy; + if (noprox) { + for (var i = 0; i < noprox.length; i += 1) { + if (this.brokerurl.indexOf(noprox[i].trim()) !== -1) { noproxy=true; } + } + } + if (prox && !noproxy) { var parsedUrl = url.parse(this.brokerurl); var proxyOpts = url.parse(prox); // true for wss @@ -134,6 +144,7 @@ module.exports = function(RED) { agent: agent } } + } } else { // construct the std mqtt:// url if (this.usetls) { diff --git a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js index 5384d1805..4c39f9f8c 100644 --- a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js +++ b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js @@ -39,10 +39,10 @@ module.exports = function(RED) { else { this.reqTimeout = 120000; } var prox, noprox; - if (process.env.http_proxy != null) { prox = process.env.http_proxy; } - if (process.env.HTTP_PROXY != null) { prox = process.env.HTTP_PROXY; } - if (process.env.no_proxy != null) { noprox = process.env.no_proxy.split(","); } - if (process.env.NO_PROXY != null) { noprox = process.env.NO_PROXY.split(","); } + if (process.env.http_proxy) { prox = process.env.http_proxy; } + if (process.env.HTTP_PROXY) { prox = process.env.HTTP_PROXY; } + if (process.env.no_proxy) { noprox = process.env.no_proxy.split(","); } + if (process.env.NO_PROXY) { noprox = process.env.NO_PROXY.split(","); } var proxyConfig = null; if (n.proxy) { @@ -88,8 +88,13 @@ module.exports = function(RED) { if (msg.method && n.method && (n.method === "use")) { method = msg.method.toUpperCase(); // use the msg parameter } + + var isHttps = (/^https/i.test(url)); + var opts = {}; opts.url = url; + // set defaultport, else when using HttpsProxyAgent, it's defaultPort of 443 will be used :(. + opts.defaultPort = isHttps?443:80; opts.timeout = node.reqTimeout; opts.method = method; opts.headers = {}; @@ -284,9 +289,10 @@ module.exports = function(RED) { opts.headers[clSet] = opts.headers['content-length']; delete opts.headers['content-length']; } + var noproxy; if (noprox) { - for (var i in noprox) { + for (var i = 0; i < noprox.length; i += 1) { if (url.indexOf(noprox[i]) !== -1) { noproxy=true; } } } diff --git a/packages/node_modules/@node-red/nodes/core/network/22-websocket.js b/packages/node_modules/@node-red/nodes/core/network/22-websocket.js index 957b7d8ed..315f3caaa 100644 --- a/packages/node_modules/@node-red/nodes/core/network/22-websocket.js +++ b/packages/node_modules/@node-red/nodes/core/network/22-websocket.js @@ -19,6 +19,8 @@ module.exports = function(RED) { var ws = require("ws"); var inspect = require("util").inspect; var url = require("url"); + var HttpsProxyAgent = require('https-proxy-agent'); + var serverUpgradeAdded = false; function handleServerUpgrade(request, socket, head) { @@ -55,7 +57,28 @@ module.exports = function(RED) { function startconn() { // Connect to remote endpoint node.tout = null; + var prox, noprox; + if (process.env.http_proxy) { prox = process.env.http_proxy; } + if (process.env.HTTP_PROXY) { prox = process.env.HTTP_PROXY; } + if (process.env.no_proxy) { noprox = process.env.no_proxy.split(","); } + if (process.env.NO_PROXY) { noprox = process.env.NO_PROXY.split(","); } + + var noproxy = false; + if (noprox) { + for (var i in noprox) { + if (node.path.indexOf(noprox[i].trim()) !== -1) { noproxy=true; } + } + } + + var agent = undefined; + if (prox && !noproxy) { + agent = new HttpsProxyAgent(prox); + } + var options = {}; + if (agent) { + options.agent = agent; + } if (node.tls) { var tlsNode = RED.nodes.getNode(node.tls); if (tlsNode) {