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
1 changed files with 17 additions and 0 deletions

View File

@ -28,6 +28,7 @@ module.exports = function(RED) {
var nodeUrl = n.url;
var isTemplatedUrl = (nodeUrl||"").indexOf("{{") != -1;
var nodeMethod = n.method || "GET";
var usePayloadAsParameters = n.usePayloadAsParameters;
if (n.tls) {
var tlsNode = RED.nodes.getNode(n.tls);
}
@ -199,6 +200,22 @@ module.exports = function(RED) {
}
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.
if (opts.headers.hasOwnProperty('content-type') && (ctSet !== 'content-type')) {
opts.headers[ctSet] = opts.headers['content-type'];