From f6a3671366bb8e36d1d32e2dc0f1e71256ddd309 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Mon, 10 May 2021 23:01:29 +0100 Subject: [PATCH] Get the http-request node got port working with Proxy --- .../nodes/core/network/21-httprequest.js | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) 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 5f1be6be9..3d7a3d88b 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 @@ -65,6 +65,7 @@ module.exports = function(RED) { } this.on("input",function(msg,nodeSend,nodeDone) { + redirectList=[]; var preRequestTimestamp = process.hrtime(); node.status({fill:"blue",shape:"dot",text:"httpin.status.requesting"}); var url = nodeUrl || msg.url; @@ -110,7 +111,7 @@ module.exports = function(RED) { var opts = {}; // set defaultport, else when using HttpsProxyAgent, it's defaultPort of 443 will be used :(. - opts.defaultPort = isHttps?443:80; + //opts.defaultPort = isHttps?443:80; opts.timeout = node.reqTimeout; opts.method = method; opts.headers = {}; @@ -339,27 +340,35 @@ module.exports = function(RED) { var match = prox.match(/^(https?:\/\/)?(.+)?:([0-9]+)?/i); if (match) { let proxyAgent; + let proxyURL = new URL(prox); let proxyOptions = { - proxy: prox, + proxy: { + protocol: proxyURL.protocol, + hostname: proxyURL.hostname, + port: proxyURL.port, + username: null, + password: null + }, maxFreeSockets: 256, maxSockets: 256, - keepAlive: true + keepAlive: false } if (proxyConfig && proxyConfig.credentials) { + // console.log("proxyConfig.creds", proxyConfig.credentials) let proxyUsername = proxyConfig.credentials.username || ''; let proxyPassword = proxyConfig.credentials.password || ''; if (proxyUsername || proxyPassword) { - var m = /^(https?:\/\/)(.*)$/.exec(prox); - proxyOptions.proxy = `${m[1]}${proxyUsername}:${proxyPassword}@${m[2]}` + proxyOptions.proxy.username = proxyUsername; + proxyOptions.password = proxyPassword; } } opts.agent = {}; - if (/^http:/.test(url)) { + // if (/^http:/.test(url)) { opts.agent.http = new HttpProxyAgent(proxyOptions) - } else { + // } else { opts.agent.https = new HttpsProxyAgent(proxyOptions) - } - console.log("ProxyOptions:",proxyOptions); + // } + // console.log("ProxyOptions:",proxyOptions); } else { node.warn("Bad proxy url: "+ prox); }