mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #1981 from jonferreira/dev
Use payload properties as parameters on a GET request
This commit is contained in:
commit
884b8da8bf
@ -25,11 +25,17 @@
|
|||||||
<option value="use" data-i18n="httpin.setby"></option>
|
<option value="use" data-i18n="httpin.setby"></option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-url"><i class="fa fa-globe"></i> <span data-i18n="httpin.label.url"></span></label>
|
<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://">
|
<input id="node-input-url" type="text" placeholder="http://">
|
||||||
</div>
|
</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">
|
<div class="form-row">
|
||||||
<input type="checkbox" id="node-input-usetls" style="display: inline-block; width: auto; vertical-align: top;">
|
<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>
|
<label for="node-input-usetls" style="width: auto" data-i18n="httpin.use-tls"></label>
|
||||||
@ -84,6 +90,7 @@
|
|||||||
name: {value:""},
|
name: {value:""},
|
||||||
method:{value:"GET"},
|
method:{value:"GET"},
|
||||||
ret: {value:"txt"},
|
ret: {value:"txt"},
|
||||||
|
usePayloadAsParameters: {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},
|
||||||
proxy: {type:"http proxy",required: false}
|
proxy: {type:"http proxy",required: false}
|
||||||
@ -114,6 +121,13 @@
|
|||||||
$('#node-input-password').val('');
|
$('#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) {
|
if (this.credentials.user || this.credentials.has_password) {
|
||||||
$('#node-input-useAuth').prop('checked', true);
|
$('#node-input-useAuth').prop('checked', true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
@ -206,6 +207,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'];
|
||||||
|
@ -377,7 +377,8 @@
|
|||||||
"upload": "Accept file uploads?",
|
"upload": "Accept file uploads?",
|
||||||
"status": "Status code",
|
"status": "Status code",
|
||||||
"headers": "Headers",
|
"headers": "Headers",
|
||||||
"other": "other"
|
"other": "other",
|
||||||
|
"usePayloadAsParameters" : "Use payload properties as parameters"
|
||||||
},
|
},
|
||||||
"setby": "- set by msg.method -",
|
"setby": "- set by msg.method -",
|
||||||
"basicauth": "Use basic authentication",
|
"basicauth": "Use basic authentication",
|
||||||
@ -405,7 +406,8 @@
|
|||||||
"deprecated-call":"Deprecated call to __method__",
|
"deprecated-call":"Deprecated call to __method__",
|
||||||
"invalid-transport":"non-http transport requested",
|
"invalid-transport":"non-http transport requested",
|
||||||
"timeout-isnan": "Timeout value is not a valid number, ignoring",
|
"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": {
|
"status": {
|
||||||
"requesting": "requesting"
|
"requesting": "requesting"
|
||||||
|
Loading…
Reference in New Issue
Block a user