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) {