mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix to allow blank password for Basic Auth in httprequest node
This commit is contained in:
parent
a3fa6dada5
commit
1f6155f118
@ -30,9 +30,9 @@ function rawBodyParser(req, res, next) {
|
||||
req.body = "";
|
||||
req._body = true;
|
||||
getBody(req, {
|
||||
limit: '1mb',
|
||||
length: req.headers['content-length'],
|
||||
encoding: 'utf8'
|
||||
limit: '1mb',
|
||||
length: req.headers['content-length'],
|
||||
encoding: 'utf8'
|
||||
}, function (err, buf) {
|
||||
if (err) return next(err);
|
||||
req.body = buf;
|
||||
@ -104,7 +104,6 @@ function HTTPIn(n) {
|
||||
this.warn("Cannot create http-in node when httpNodeRoot set to false");
|
||||
}
|
||||
}
|
||||
|
||||
RED.nodes.registerType("http in",HTTPIn);
|
||||
|
||||
|
||||
@ -112,22 +111,21 @@ function HTTPOut(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
var node = this;
|
||||
this.on("input",function(msg) {
|
||||
if (msg.res) {
|
||||
if (msg.headers) {
|
||||
msg.res.set(msg.headers);
|
||||
}
|
||||
var statusCode = msg.statusCode || 200;
|
||||
if (typeof msg.payload == "object" && !Buffer.isBuffer(msg.payload)) {
|
||||
msg.res.jsonp(statusCode,msg.payload);
|
||||
} else {
|
||||
msg.res.send(statusCode,msg.payload);
|
||||
}
|
||||
} else {
|
||||
node.warn("No response object");
|
||||
if (msg.res) {
|
||||
if (msg.headers) {
|
||||
msg.res.set(msg.headers);
|
||||
}
|
||||
var statusCode = msg.statusCode || 200;
|
||||
if (typeof msg.payload == "object" && !Buffer.isBuffer(msg.payload)) {
|
||||
msg.res.jsonp(statusCode,msg.payload);
|
||||
} else {
|
||||
msg.res.send(statusCode,msg.payload);
|
||||
}
|
||||
} else {
|
||||
node.warn("No response object");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType("http response",HTTPOut);
|
||||
|
||||
function HTTPRequest(n) {
|
||||
@ -136,12 +134,7 @@ function HTTPRequest(n) {
|
||||
var nodeMethod = n.method || "GET";
|
||||
var node = this;
|
||||
var credentials = RED.nodes.getCredentials(n.id);
|
||||
if (credentials) {
|
||||
this.username = credentials.user;
|
||||
this.password = credentials.password;
|
||||
}
|
||||
this.on("input",function(msg) {
|
||||
|
||||
var url = msg.url||nodeUrl;
|
||||
var method = (msg.method||nodeMethod).toUpperCase();
|
||||
var opts = urllib.parse(url);
|
||||
@ -150,24 +143,24 @@ function HTTPRequest(n) {
|
||||
opts.headers = msg.headers;
|
||||
}
|
||||
if (credentials) {
|
||||
opts.auth = credentials.user+":"+credentials.password;
|
||||
opts.auth = credentials.user+":"+(credentials.password||"");
|
||||
}
|
||||
var req = ((/^https/.test(url))?https:http).request(opts,function(res) {
|
||||
res.setEncoding('utf8');
|
||||
msg.statusCode = res.statusCode;
|
||||
msg.headers = res.headers;
|
||||
msg.payload = "";
|
||||
res.on('data',function(chunk) {
|
||||
msg.payload += chunk;
|
||||
});
|
||||
res.on('end',function() {
|
||||
node.send(msg);
|
||||
});
|
||||
res.setEncoding('utf8');
|
||||
msg.statusCode = res.statusCode;
|
||||
msg.headers = res.headers;
|
||||
msg.payload = "";
|
||||
res.on('data',function(chunk) {
|
||||
msg.payload += chunk;
|
||||
});
|
||||
res.on('end',function() {
|
||||
node.send(msg);
|
||||
});
|
||||
});
|
||||
req.on('error',function(err) {
|
||||
msg.payload = err.toString();
|
||||
msg.statusCode = err.code;
|
||||
node.send(msg);
|
||||
msg.payload = err.toString();
|
||||
msg.statusCode = err.code;
|
||||
node.send(msg);
|
||||
});
|
||||
if (msg.payload && (method == "POST" || method == "PUT") ) {
|
||||
if (typeof msg.payload === "string" || Buffer.isBuffer(msg.payload)) {
|
||||
@ -179,11 +172,8 @@ function HTTPRequest(n) {
|
||||
}
|
||||
}
|
||||
req.end();
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType("http request",HTTPRequest);
|
||||
|
||||
var querystring = require('querystring');
|
||||
@ -224,5 +214,3 @@ RED.httpAdmin.post('/http-request/:id',function(req,res) {
|
||||
res.send(200);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user