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 3d7a3d88b..00226d3fd 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,7 +65,8 @@ module.exports = function(RED) { } this.on("input",function(msg,nodeSend,nodeDone) { - redirectList=[]; + //reset redirectList on each request + redirectList = []; var preRequestTimestamp = process.hrtime(); node.status({fill:"blue",shape:"dot",text:"httpin.status.requesting"}); var url = nodeUrl || msg.url; @@ -107,11 +108,12 @@ module.exports = function(RED) { method = msg.method.toUpperCase(); // use the msg parameter } - var isHttps = (/^https/i.test(url)); + // var isHttps = (/^https/i.test(url)); var opts = {}; // set defaultport, else when using HttpsProxyAgent, it's defaultPort of 443 will be used :(. - //opts.defaultPort = isHttps?443:80; + // Had to remove this to get http->https redirect to work + // opts.defaultPort = isHttps?443:80; opts.timeout = node.reqTimeout; opts.method = method; opts.headers = {}; @@ -341,6 +343,7 @@ module.exports = function(RED) { if (match) { let proxyAgent; let proxyURL = new URL(prox); + //set username/password to null to stop empty creds header let proxyOptions = { proxy: { protocol: proxyURL.protocol, @@ -351,24 +354,22 @@ module.exports = function(RED) { }, maxFreeSockets: 256, maxSockets: 256, - keepAlive: false + keepAlive: true } if (proxyConfig && proxyConfig.credentials) { - // console.log("proxyConfig.creds", proxyConfig.credentials) let proxyUsername = proxyConfig.credentials.username || ''; let proxyPassword = proxyConfig.credentials.password || ''; if (proxyUsername || proxyPassword) { proxyOptions.proxy.username = proxyUsername; - proxyOptions.password = proxyPassword; + proxyOptions.proxy.password = proxyPassword; } } - opts.agent = {}; - // if (/^http:/.test(url)) { - opts.agent.http = new HttpProxyAgent(proxyOptions) - // } else { - opts.agent.https = new HttpsProxyAgent(proxyOptions) - // } - // console.log("ProxyOptions:",proxyOptions); + //need both incase of http -> https redirec + opts.agent = { + http: new HttpProxyAgent(proxyOptions), + https: new HttpsProxyAgent(proxyOptions) + }; + } else { node.warn("Bad proxy url: "+ prox); }