mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00: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:
		| @@ -30,6 +30,7 @@ function Xml2jsNode(n) { | |||||||
|     this.useEyes = n.useEyes; |     this.useEyes = n.useEyes; | ||||||
|     var node = this; |     var node = this; | ||||||
|     this.on("input", function(msg) { |     this.on("input", function(msg) { | ||||||
|  |         try { | ||||||
| 		    parseString(msg.payload, function (err, result) { | 		    parseString(msg.payload, function (err, result) { | ||||||
| 		        if (err) { node.error(err); } | 		        if (err) { node.error(err); } | ||||||
| 		        else { | 		        else { | ||||||
| @@ -41,6 +42,8 @@ function Xml2jsNode(n) { | |||||||
| 		            } | 		            } | ||||||
| 		        } | 		        } | ||||||
| 		    }); | 		    }); | ||||||
|  | 		} | ||||||
|  | 		catch(e) { console.log(e); } | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| RED.nodes.registerType("xml2js",Xml2jsNode); | RED.nodes.registerType("xml2js",Xml2jsNode); | ||||||
|   | |||||||
| @@ -79,9 +79,7 @@ function HTTPRequest(n) { | |||||||
|     var httplib = (/^https/.test(url))?https:http; |     var httplib = (/^https/.test(url))?https:http; | ||||||
|     var node = this; |     var node = this; | ||||||
|     this.on("input",function(msg) { |     this.on("input",function(msg) { | ||||||
| 	        if (msg.url) { |  | ||||||
| 	            httplib = (/^https/.test(msg.url))?https:http; |  | ||||||
| 	        } |  | ||||||
|             var opts = urllib.parse(msg.url||url); |             var opts = urllib.parse(msg.url||url); | ||||||
|             opts.method = (msg.method||method).toUpperCase(); |             opts.method = (msg.method||method).toUpperCase(); | ||||||
|             if (msg.headers) { |             if (msg.headers) { | ||||||
| @@ -89,16 +87,14 @@ function HTTPRequest(n) { | |||||||
|             } |             } | ||||||
|             var req = httplib.request(opts,function(res) { |             var req = httplib.request(opts,function(res) { | ||||||
|                     res.setEncoding('utf8'); |                     res.setEncoding('utf8'); | ||||||
| 	                var message = { |                     msg.statusCode = res.statusCode; | ||||||
| 	                    statusCode: res.statusCode, |                     msg.headers = res.headers; | ||||||
| 	                    headers: res.headers, |                     msg.payload = ""; | ||||||
| 	                    payload: "" |  | ||||||
| 	                }; |  | ||||||
|                     res.on('data',function(chunk) { |                     res.on('data',function(chunk) { | ||||||
| 	                        message.payload += chunk; |                             msg.payload += chunk; | ||||||
|                     }); |                     }); | ||||||
|                     res.on('end',function() { |                     res.on('end',function() { | ||||||
| 	                        node.send(message); |                             node.send(msg); | ||||||
|                     }); |                     }); | ||||||
|             }); |             }); | ||||||
|             req.on('error',function(err) { |             req.on('error',function(err) { | ||||||
| @@ -106,7 +102,7 @@ function HTTPRequest(n) { | |||||||
|                     msg.statusCode = err.code; |                     msg.statusCode = err.code; | ||||||
|                     node.send(msg); |                     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)) { |                 if (typeof msg.payload === "string" || Buffer.isBuffer(msg.payload)) { | ||||||
|                     req.write(msg.payload); |                     req.write(msg.payload); | ||||||
|                 } else if (typeof msg.payload == "number") { |                 } else if (typeof msg.payload == "number") { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user