mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Get the http-request node got port working with Proxy
This commit is contained in:
parent
e23f20227a
commit
f6a3671366
@ -65,6 +65,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.on("input",function(msg,nodeSend,nodeDone) {
|
this.on("input",function(msg,nodeSend,nodeDone) {
|
||||||
|
redirectList=[];
|
||||||
var preRequestTimestamp = process.hrtime();
|
var preRequestTimestamp = process.hrtime();
|
||||||
node.status({fill:"blue",shape:"dot",text:"httpin.status.requesting"});
|
node.status({fill:"blue",shape:"dot",text:"httpin.status.requesting"});
|
||||||
var url = nodeUrl || msg.url;
|
var url = nodeUrl || msg.url;
|
||||||
@ -110,7 +111,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
var opts = {};
|
var opts = {};
|
||||||
// set defaultport, else when using HttpsProxyAgent, it's defaultPort of 443 will be used :(.
|
// 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.timeout = node.reqTimeout;
|
||||||
opts.method = method;
|
opts.method = method;
|
||||||
opts.headers = {};
|
opts.headers = {};
|
||||||
@ -339,27 +340,35 @@ module.exports = function(RED) {
|
|||||||
var match = prox.match(/^(https?:\/\/)?(.+)?:([0-9]+)?/i);
|
var match = prox.match(/^(https?:\/\/)?(.+)?:([0-9]+)?/i);
|
||||||
if (match) {
|
if (match) {
|
||||||
let proxyAgent;
|
let proxyAgent;
|
||||||
|
let proxyURL = new URL(prox);
|
||||||
let proxyOptions = {
|
let proxyOptions = {
|
||||||
proxy: prox,
|
proxy: {
|
||||||
|
protocol: proxyURL.protocol,
|
||||||
|
hostname: proxyURL.hostname,
|
||||||
|
port: proxyURL.port,
|
||||||
|
username: null,
|
||||||
|
password: null
|
||||||
|
},
|
||||||
maxFreeSockets: 256,
|
maxFreeSockets: 256,
|
||||||
maxSockets: 256,
|
maxSockets: 256,
|
||||||
keepAlive: true
|
keepAlive: false
|
||||||
}
|
}
|
||||||
if (proxyConfig && proxyConfig.credentials) {
|
if (proxyConfig && proxyConfig.credentials) {
|
||||||
|
// console.log("proxyConfig.creds", proxyConfig.credentials)
|
||||||
let proxyUsername = proxyConfig.credentials.username || '';
|
let proxyUsername = proxyConfig.credentials.username || '';
|
||||||
let proxyPassword = proxyConfig.credentials.password || '';
|
let proxyPassword = proxyConfig.credentials.password || '';
|
||||||
if (proxyUsername || proxyPassword) {
|
if (proxyUsername || proxyPassword) {
|
||||||
var m = /^(https?:\/\/)(.*)$/.exec(prox);
|
proxyOptions.proxy.username = proxyUsername;
|
||||||
proxyOptions.proxy = `${m[1]}${proxyUsername}:${proxyPassword}@${m[2]}`
|
proxyOptions.password = proxyPassword;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
opts.agent = {};
|
opts.agent = {};
|
||||||
if (/^http:/.test(url)) {
|
// if (/^http:/.test(url)) {
|
||||||
opts.agent.http = new HttpProxyAgent(proxyOptions)
|
opts.agent.http = new HttpProxyAgent(proxyOptions)
|
||||||
} else {
|
// } else {
|
||||||
opts.agent.https = new HttpsProxyAgent(proxyOptions)
|
opts.agent.https = new HttpsProxyAgent(proxyOptions)
|
||||||
}
|
// }
|
||||||
console.log("ProxyOptions:",proxyOptions);
|
// console.log("ProxyOptions:",proxyOptions);
|
||||||
} else {
|
} else {
|
||||||
node.warn("Bad proxy url: "+ prox);
|
node.warn("Bad proxy url: "+ prox);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user