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

Update 21-httprequest.js

This commit is contained in:
jonferreira 2018-11-15 17:11:27 +00:00 committed by GitHub
parent 6c75baecb2
commit 21ce23d27d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,6 +28,7 @@ module.exports = function(RED) {
var nodeUrl = n.url; var nodeUrl = n.url;
var isTemplatedUrl = (nodeUrl||"").indexOf("{{") != -1; var isTemplatedUrl = (nodeUrl||"").indexOf("{{") != -1;
var nodeMethod = n.method || "GET"; var nodeMethod = n.method || "GET";
var usePayloadAsParameters = n.usePayloadAsParameters;
if (n.tls) { if (n.tls) {
var tlsNode = RED.nodes.getNode(n.tls); var tlsNode = RED.nodes.getNode(n.tls);
} }
@ -199,6 +200,22 @@ module.exports = function(RED) {
} }
opts.body = payload; opts.body = payload;
} }
if (method == 'GET' && typeof msg.payload !== "undefined" && usePayloadAsParameters) {
if (typeof msg.payload === "object") {
if(opts.url.indexOf("?") !== -1) {
opts.url += "&" + querystring.stringify(msg.payload);
} else {
opts.url += "?" + querystring.stringify(msg.payload);
}
} else {
//I'm not sure where to set "httpin.errors.unvalid-payload" :(
node.error(RED._("httpin.errors.invalid-payload"),msg);
return;
}
}
// revert to user supplied Capitalisation if needed. // revert to user supplied Capitalisation if needed.
if (opts.headers.hasOwnProperty('content-type') && (ctSet !== 'content-type')) { if (opts.headers.hasOwnProperty('content-type') && (ctSet !== 'content-type')) {
opts.headers[ctSet] = opts.headers['content-type']; opts.headers[ctSet] = opts.headers['content-type'];