Merge pull request #1981 from jonferreira/dev

Use payload properties as parameters on a GET request
This commit is contained in:
Nick O'Leary 2019-02-04 20:43:45 +00:00 committed by GitHub
commit 884b8da8bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 2 deletions

View File

@ -25,11 +25,17 @@
<option value="use" data-i18n="httpin.setby"></option>
</select>
</div>
<div class="form-row">
<label for="node-input-url"><i class="fa fa-globe"></i> <span data-i18n="httpin.label.url"></span></label>
<input id="node-input-url" type="text" placeholder="http://">
</div>
<div class="form-row node-input-usePayloadAsParameters-row">
<input type="checkbox" id="node-input-usePayloadAsParameters" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-usePayloadAsParameters" style="width: auto" data-i18n="httpin.label.usePayloadAsParameters"></label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-usetls" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-usetls" style="width: auto" data-i18n="httpin.use-tls"></label>
@ -84,6 +90,7 @@
name: {value:""},
method:{value:"GET"},
ret: {value:"txt"},
usePayloadAsParameters: {value: false},
url:{value:"",validate:function(v) { return (v.trim().length === 0) || (v.indexOf("://") === -1) || (v.trim().indexOf("http") === 0)} },
tls: {type:"tls-config",required: false},
proxy: {type:"http proxy",required: false}
@ -114,6 +121,13 @@
$('#node-input-password').val('');
}
});
$("#node-input-method").change(function() {
if ($(this).val() == "GET") {
$(".node-input-usePayloadAsParameters-row").show();
} else {
$(".node-input-usePayloadAsParameters-row").hide();
}
});
if (this.credentials.user || this.credentials.has_password) {
$('#node-input-useAuth').prop('checked', true);
} else {

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);
}
@ -206,6 +207,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'];

View File

@ -377,7 +377,8 @@
"upload": "Accept file uploads?",
"status": "Status code",
"headers": "Headers",
"other": "other"
"other": "other",
"usePayloadAsParameters" : "Use payload properties as parameters"
},
"setby": "- set by msg.method -",
"basicauth": "Use basic authentication",
@ -405,7 +406,8 @@
"deprecated-call":"Deprecated call to __method__",
"invalid-transport":"non-http transport requested",
"timeout-isnan": "Timeout value is not a valid number, ignoring",
"timeout-isnegative": "Timeout value is negative, ignoring"
"timeout-isnegative": "Timeout value is negative, ignoring",
"invalid-payload": "Invalid payload"
},
"status": {
"requesting": "requesting"