1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Allow http request node to pass through existing msg properties rather than wiping clean (in case needed on other side...)

Also one more try / catch to xml parser... could still barf if provoked.
This commit is contained in:
Dave C-J 2013-10-23 21:27:54 +01:00
parent 30f3a46d46
commit f1f00da1a8
2 changed files with 89 additions and 90 deletions

View File

@ -30,6 +30,7 @@ function Xml2jsNode(n) {
this.useEyes = n.useEyes;
var node = this;
this.on("input", function(msg) {
try {
parseString(msg.payload, function (err, result) {
if (err) { node.error(err); }
else {
@ -41,6 +42,8 @@ function Xml2jsNode(n) {
}
}
});
}
catch(e) { console.log(e); }
});
}
RED.nodes.registerType("xml2js",Xml2jsNode);

View File

@ -79,9 +79,7 @@ function HTTPRequest(n) {
var httplib = (/^https/.test(url))?https:http;
var node = this;
this.on("input",function(msg) {
if (msg.url) {
httplib = (/^https/.test(msg.url))?https:http;
}
var opts = urllib.parse(msg.url||url);
opts.method = (msg.method||method).toUpperCase();
if (msg.headers) {
@ -89,16 +87,14 @@ function HTTPRequest(n) {
}
var req = httplib.request(opts,function(res) {
res.setEncoding('utf8');
var message = {
statusCode: res.statusCode,
headers: res.headers,
payload: ""
};
msg.statusCode = res.statusCode;
msg.headers = res.headers;
msg.payload = "";
res.on('data',function(chunk) {
message.payload += chunk;
msg.payload += chunk;
});
res.on('end',function() {
node.send(message);
node.send(msg);
});
});
req.on('error',function(err) {
@ -106,7 +102,7 @@ function HTTPRequest(n) {
msg.statusCode = err.code;
node.send(msg);
});
if (msg.payload && (method == "POST" || method == "PUT") ) {
if (msg.payload && (method == "PUSH" || method == "PUT") ) {
if (typeof msg.payload === "string" || Buffer.isBuffer(msg.payload)) {
req.write(msg.payload);
} else if (typeof msg.payload == "number") {