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

improve UI around payloadHandling

This commit is contained in:
Steve-Mcl 2022-11-29 13:38:09 +00:00
parent 3ed5969e87
commit 3a5cdbc8ae
11 changed files with 54 additions and 16 deletions

View File

@ -33,11 +33,12 @@
</div> </div>
<div class="form-row node-input-paytoqs-row"> <div class="form-row node-input-paytoqs-row">
<label for="node-input-paytoqs"><span data-i18n="common.label.payload"></span></label> <label for="node-input-paytoqs"><span data-i18n="httpin.label.paytoqs.label"></span></label>
<select id="node-input-paytoqs" style="width: 70%;"> <select id="node-input-paytoqs" style="width: 70%;">
<option value="ignore" data-i18n="httpin.label.paytoqs.ignore"></option> <option value="ignore" data-i18n="httpin.label.paytoqs.ignore"></option>
<option value="query" data-i18n="httpin.label.paytoqs.query"></option> <option value="query" data-i18n="httpin.label.paytoqs.query"></option>
<option value="body" data-i18n="httpin.label.paytoqs.body"></option> <option value="body" data-i18n="httpin.label.paytoqs.body"></option>
<option value="setby" data-i18n="httpin.label.paytoqs.setby"></option>
</select> </select>
</div> </div>
@ -290,7 +291,7 @@
RED.tray.resize(); RED.tray.resize();
}); });
$("#node-input-method").on("change", function() { $("#node-input-method").on("change", function() {
if ($(this).val() == "GET") { if ($(this).val() == "GET" || $(this).val() == "use") {
$(".node-input-paytoqs-row").show(); $(".node-input-paytoqs-row").show();
} else { } else {
$(".node-input-paytoqs-row").hide(); $(".node-input-paytoqs-row").hide();

View File

@ -16,7 +16,7 @@
module.exports = function(RED) { module.exports = function(RED) {
"use strict"; "use strict";
const got = require("got"); const got = require("got").default;
const {CookieJar} = require("tough-cookie"); const {CookieJar} = require("tough-cookie");
const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent'); const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent');
const FormData = require('form-data'); const FormData = require('form-data');
@ -191,15 +191,21 @@ in your Node-RED user directory (${RED.settings.userDir}).
} }
} }
/** @type {boolean|'query'|'body'} */
let payloadHandling = node.paytoqs
let method = nodeMethod.toUpperCase() || "GET"; let method = nodeMethod.toUpperCase() || "GET";
if (msg.method && n.method && (n.method !== "use")) { // warn if override option not set if (msg.method && n.method && (n.method !== "use")) { // warn if override option not set
node.warn(RED._("common.errors.nooverride")); node.warn(RED._("common.errors.nooverride"));
} }
if (msg.method && n.method && (n.method === "use")) { if (msg.method && n.method && (n.method === "use")) {
method = msg.method.toUpperCase(); // use the msg parameter method = msg.method.toUpperCase(); // use the msg parameter
payloadHandling = msg.payloadHandling }
/** @type {boolean|'query'|'body'|'setby'} */
let payloadHandling = node.paytoqs
if (msg.payloadHandling && payloadHandling && (payloadHandling !== "setby")) { // warn if override option not set
node.warn(RED._("common.errors.nooverride"));
}
if (msg.payloadHandling && payloadHandling && (payloadHandling === "setby")) {
payloadHandling = msg.payloadHandling // use the msg parameter
} }
if (payloadHandling === true) { payloadHandling = "query" } if (payloadHandling === true) { payloadHandling = "query" }

View File

@ -449,9 +449,11 @@
"headers": "Kopfzeilen", "headers": "Kopfzeilen",
"other": "andere", "other": "andere",
"paytoqs": { "paytoqs": {
"label": "Payload (GET)",
"ignore": "Ignorieren", "ignore": "Ignorieren",
"query": "Anfügen an query-string-Parameter", "query": "Anfügen an query-string-Parameter",
"body": "Senden als request-body" "body": "Senden als request-body",
"setby": "Durch msg.payloadHandling festgelegt"
}, },
"utf8String": "UTF-8-String", "utf8String": "UTF-8-String",
"binaryBuffer": "Binärer Buffer", "binaryBuffer": "Binärer Buffer",

View File

@ -509,9 +509,11 @@
"headers": "Headers", "headers": "Headers",
"other": "other", "other": "other",
"paytoqs": { "paytoqs": {
"label": "Payload (GET)",
"ignore": "Ignore", "ignore": "Ignore",
"query": "Append to query-string parameters", "query": "Append to query-string parameters",
"body": "Send as request body" "body": "Send as request body",
"setby": "- set by msg.payloadHandling -"
}, },
"utf8String": "UTF8 string", "utf8String": "UTF8 string",
"binaryBuffer": "binary buffer", "binaryBuffer": "binary buffer",

View File

@ -30,6 +30,10 @@
<dd>If set, can be used to send cookies with the request.</dd> <dd>If set, can be used to send cookies with the request.</dd>
<dt class="optional">payload</dt> <dt class="optional">payload</dt>
<dd>Sent as the body of the request.</dd> <dd>Sent as the body of the request.</dd>
<dt class="optional">payloadHandling <span class="property-type">string</span></dt>
<dd>Only valid with GET requests. If set to <b>"- use msg.payloadHandling -"</b> in the node configuration, this property
indicates how the <code>payload</code> will be sent. <code>msg.payloadHandling</code> should contain either
<code>"query"</code> or <code>"body"</code> otherwise the payload will not be sent with the GET request</dd>
<dt class="optional">rejectUnauthorized</dt> <dt class="optional">rejectUnauthorized</dt>
<dd>If set to <code>false</code>, allows requests to be made to https sites that use <dd>If set to <code>false</code>, allows requests to be made to https sites that use
self signed certificates.</dd> self signed certificates.</dd>

View File

@ -509,9 +509,11 @@
"headers": "ヘッダ", "headers": "ヘッダ",
"other": "その他", "other": "その他",
"paytoqs": { "paytoqs": {
"label": "ペイロード (GET)",
"ignore": "無視", "ignore": "無視",
"query": "クエリパラメータに追加", "query": "クエリパラメータに追加",
"body": "リクエストボディとして送信" "body": "リクエストボディとして送信",
"setby": "- msg.payloadHandlingに定義 -"
}, },
"utf8String": "UTF8文字列", "utf8String": "UTF8文字列",
"binaryBuffer": "バイナリバッファ", "binaryBuffer": "バイナリバッファ",

View File

@ -387,7 +387,13 @@
"status": "상태코드", "status": "상태코드",
"headers": "헤더", "headers": "헤더",
"other": "그 외", "other": "그 외",
"paytoqs" : "msg.payload를 쿼리 파라미터에 추가", "paytoqs": {
"label": "페이로드(GET)",
"ignore": "무시",
"query": "msg.payload를 쿼리 파라미터에 추가",
"body": "본문에 msg.payload 추가",
"setby": "- msg.payloadHandling에 의해 설정됨 -"
},
"utf8String": "UTF8문자열", "utf8String": "UTF8문자열",
"binaryBuffer": "바이너리 버퍼", "binaryBuffer": "바이너리 버퍼",
"jsonObject": "JSON오브젝트", "jsonObject": "JSON오브젝트",

View File

@ -411,9 +411,11 @@
"headers": "Заголовки", "headers": "Заголовки",
"other": "другое", "other": "другое",
"paytoqs": { "paytoqs": {
"label": "Данные (GET)",
"ignore": "Игнорировать", "ignore": "Игнорировать",
"query": "Добавлять к параметрам строки запроса", "query": "Добавлять к параметрам строки запроса",
"body": "Отправлять как тело запроса" "body": "Отправлять как тело запроса",
"setby": "- устанавливается через msg.payloadHandling -"
}, },
"utf8String": "Строка UTF8", "utf8String": "Строка UTF8",
"binaryBuffer": "двоичный буфер", "binaryBuffer": "двоичный буфер",

View File

@ -407,7 +407,13 @@
"status": "状态码", "status": "状态码",
"headers": "头", "headers": "头",
"other": "其他", "other": "其他",
"paytoqs": "将msg.payload附加为查询字符串参数", "paytoqs": {
"label": "有效负载(仅限 GET",
"ignore": "漠视",
"query": "将msg.payload附加为查询字符串参数",
"body": "在请求正文中发送负载",
"setby": "- 用 msg.payloadHandling 设定 -"
},
"utf8String": "UTF8格式的字符串", "utf8String": "UTF8格式的字符串",
"binaryBuffer": "二进制buffer", "binaryBuffer": "二进制buffer",
"jsonObject": "解析的JSON对象", "jsonObject": "解析的JSON对象",

View File

@ -411,7 +411,13 @@
"status": "狀態碼", "status": "狀態碼",
"headers": "Header", "headers": "Header",
"other": "其他", "other": "其他",
"paytoqs": "將msg.payload附加為查詢字符串參數", "paytoqs": {
"label": "有效負載(僅限 GET",
"ignore": "漠視",
"query": "將msg.payload附加為查詢字符串參數",
"body": "在請求正文中發送負載",
"setby": "- 用 msg.payloadHandling 設定 -"
},
"utf8String": "UTF8格式的字符串", "utf8String": "UTF8格式的字符串",
"binaryBuffer": "二進制buffer", "binaryBuffer": "二進制buffer",
"jsonObject": "解析的JSON對象", "jsonObject": "解析的JSON對象",

View File

@ -299,10 +299,11 @@ describe('HTTP Request Node', function() {
// GOT never sent a body. (there is nothing in params/query/body) // GOT never sent a body. (there is nothing in params/query/body)
// Oddly, if we set options.json (instead of options.body) in the GOT // Oddly, if we set options.json (instead of options.body) in the GOT
// request, then req.body will have the values! // request, then req.body will have the values!
// Has the 21-httprequest node ever been able to send a payload in body //I suspect the GOT lib *is* sending body on a GET request since an
// for a GET request? // error is thrown if we try to set options.body on a GET request without
// setting options.allowGetBody to true.
res.json({ res.json({
// body:JSON.parse(req.body), // body:JSON.parse(req.body), //req.body is empty!
url: req.originalUrl url: req.originalUrl
}); });
}) })