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

First pass at adding support for GET requests

with a body
This commit is contained in:
Ben Hardill 2020-02-25 21:28:15 +00:00
parent c9ad5bea93
commit 37bcd5c603
No known key found for this signature in database
GPG Key ID: 74DD076979ABB1E7
3 changed files with 36 additions and 3 deletions

View File

@ -33,8 +33,12 @@
</div> </div>
<div class="form-row node-input-paytoqs-row"> <div class="form-row node-input-paytoqs-row">
<input type="checkbox" id="node-input-paytoqs" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-input-paytox" style="width: auto" data-i18n="httpin.label.paytoqs"></label>
<label for="node-input-paytoqs" style="width: auto" data-i18n="httpin.label.paytoqs"></label> <select id="node-input-paytox">
<option value="ignore">Ignore</option>
<option value="query">Query String</option>
<option value="body">Request Body</option>
</select>
</div> </div>
<div class="form-row"> <div class="form-row">
@ -106,6 +110,7 @@
method:{value:"GET"}, method:{value:"GET"},
ret: {value:"txt"}, ret: {value:"txt"},
paytoqs: {value: false}, paytoqs: {value: false},
paytobody: {value: false},
url:{value:"",validate:function(v) { return (v.trim().length === 0) || (v.indexOf("://") === -1) || (v.trim().indexOf("http") === 0)} }, url:{value:"",validate:function(v) { return (v.trim().length === 0) || (v.indexOf("://") === -1) || (v.trim().indexOf("http") === 0)} },
tls: {type:"tls-config",required: false}, tls: {type:"tls-config",required: false},
persist: {value:false}, persist: {value:false},
@ -168,6 +173,13 @@
$(".node-input-paytoqs-row").hide(); $(".node-input-paytoqs-row").hide();
} }
}); });
if (this.paytoqs) {
$("#node-input-paytox").val("query");
} else if (this.paytobody) {
$("#node-input-paytox").val("body");
} else {
$("#node-input-paytox").val("ignore");
}
if (this.authType) { if (this.authType) {
$('#node-input-useAuth').prop('checked', true); $('#node-input-useAuth').prop('checked', true);
$("#node-input-authType-select").val(this.authType); $("#node-input-authType-select").val(this.authType);
@ -226,6 +238,18 @@
if (!$("#node-input-useProxy").is(":checked")) { if (!$("#node-input-useProxy").is(":checked")) {
$("#node-input-proxy").val("_ADD_"); $("#node-input-proxy").val("_ADD_");
} }
var payto = $("#node-input-paytox").val();
if(payto == "query") {
this.paytoqs = true;
this.paytobody = false;
} else if (payto == "body") {
this.paytoqs = false;
this.paytobody = true;
} else {
this.paytoqs = false;
this.paytobody = false;
}
} }
}); });
</script> </script>

View File

@ -29,6 +29,7 @@ module.exports = function(RED) {
var isTemplatedUrl = (nodeUrl||"").indexOf("{{") != -1; var isTemplatedUrl = (nodeUrl||"").indexOf("{{") != -1;
var nodeMethod = n.method || "GET"; var nodeMethod = n.method || "GET";
var paytoqs = n.paytoqs; var paytoqs = n.paytoqs;
var paytobody = n.paytobody;
var nodeHTTPPersistent = n["persist"]; var nodeHTTPPersistent = n["persist"];
if (n.tls) { if (n.tls) {
var tlsNode = RED.nodes.getNode(n.tls); var tlsNode = RED.nodes.getNode(n.tls);
@ -277,6 +278,14 @@ module.exports = function(RED) {
node.error(RED._("httpin.errors.invalid-payload"),msg); node.error(RED._("httpin.errors.invalid-payload"),msg);
nodeDone(); nodeDone();
return; return;
}
} else if ( method == "GET" && typeof msg.payload !== "undefined" && paytobody) {
if (typeof msg.payload === "object") {
opts.body = JSON.stringify(msg.payload);
} else if (typeof msg.payload == "number") {
opts.body = msg.payload+"";
} else if (typeof msg.payload === "string" || Buffer.isBuffer(msg.payload)) {
opts.body = msg.payload;
} }
} }

View File

@ -398,7 +398,7 @@
"status": "Status code", "status": "Status code",
"headers": "Headers", "headers": "Headers",
"other": "other", "other": "other",
"paytoqs" : "Append msg.payload as query string parameters", "paytoqs" : "Append msg.payload as",
"utf8String": "UTF8 string", "utf8String": "UTF8 string",
"binaryBuffer": "binary buffer", "binaryBuffer": "binary buffer",
"jsonObject": "parsed JSON object", "jsonObject": "parsed JSON object",