Add no_proxy to http-request node.

also make it support HTTP_PROXY and NO_PROXY (ie uppercase)
This commit is contained in:
dceejay 2015-05-19 11:07:54 +01:00
parent 38ab1550d2
commit 956050434f
1 changed files with 17 additions and 4 deletions

View File

@ -77,13 +77,13 @@ module.exports = function(RED) {
}
var httpMiddleware = function(req,res,next) { next(); }
if (RED.settings.httpNodeMiddleware) {
if (typeof RED.settings.httpNodeMiddleware === "function") {
httpMiddleware = RED.settings.httpNodeMiddleware;
}
}
var metricsHandler = function(req,res,next) { next(); }
if (this.metric()) {
@ -185,6 +185,13 @@ module.exports = function(RED) {
var nodeMethod = n.method || "GET";
this.ret = n.ret || "txt";
var node = this;
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(","); }
this.on("input",function(msg) {
var preRequestTimestamp = process.hrtime();
node.status({fill:"blue",shape:"dot",text:"requesting"});
@ -256,8 +263,14 @@ module.exports = function(RED) {
}
}
var urltotest = url;
if (process.env.http_proxy != null) {
var match = process.env.http_proxy.match(/^(http:\/\/)?([^:\/]+)(:([0-9]+))?/i);
var noproxy;
if (noprox) {
for (var i in noprox) {
if (url.indexOf(noprox[i]) !== -1) { noproxy=true; }
}
}
if (prox && !noproxy) {
var match = prox.match(/^(http:\/\/)?([^:\/]+)(:([0-9]+))?/i);
if (match) {
opts.protocol = "http:";
opts.headers['Host'] = opts.host;