From 524021f0fa287743a77aa961d6020b6555b1009e Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Mon, 15 May 2017 22:04:47 +0100 Subject: [PATCH] http request node add transport validity check and warn. --- nodes/core/io/21-httprequest.html | 5 ++++- nodes/core/io/21-httprequest.js | 6 +++++- nodes/core/locales/en-US/messages.json | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/nodes/core/io/21-httprequest.html b/nodes/core/io/21-httprequest.html index 0c23d0f11..36f8900ed 100644 --- a/nodes/core/io/21-httprequest.html +++ b/nodes/core/io/21-httprequest.html @@ -103,7 +103,7 @@ name: {value:""}, method:{value:"GET"}, ret: {value:"txt"}, - url:{value:""}, + url:{value:"",validate:function(v) { return (v.trim().length === 0) || (v.indexOf("://") === -1) || (v.trim().indexOf("http") === 0)} }, tls: {type:"tls-config",required: false} }, credentials: { @@ -112,6 +112,9 @@ }, inputs:1, outputs:1, + outputLabels: function(i) { + return ({txt:"UTF8 string", bin:"binary buffer", obj:"parsed JSON object"}[this.ret]); + }, icon: "white-globe.png", label: function() { return this.name||this._("httpin.httpreq"); diff --git a/nodes/core/io/21-httprequest.js b/nodes/core/io/21-httprequest.js index d6d6f42de..0b39642c3 100644 --- a/nodes/core/io/21-httprequest.js +++ b/nodes/core/io/21-httprequest.js @@ -53,9 +53,13 @@ module.exports = function(RED) { } if (!url) { node.error(RED._("httpin.errors.no-url"),msg); - return; } // url must start http:// or https:// so assume http:// if not set + if (url.indexOf("://") !== -1 && url.indexOf("http") !== 0) { + node.warn(RED._("httpin.errors.invalid-transport")); + node.status({fill:"red",shape:"ring",text:"httpin.errors.invalid-transport"}); + return; + } if (!((url.indexOf("http://") === 0) || (url.indexOf("https://") === 0))) { if (tlsNode) { url = "https://"+url; diff --git a/nodes/core/locales/en-US/messages.json b/nodes/core/locales/en-US/messages.json index cf8cf1a71..c5bcc1021 100644 --- a/nodes/core/locales/en-US/messages.json +++ b/nodes/core/locales/en-US/messages.json @@ -355,7 +355,8 @@ "no-response": "No response object", "json-error": "JSON parse error", "no-url": "No url specified", - "deprecated-call":"Deprecated call to __method__" + "deprecated-call":"Deprecated call to __method__", + "invalid-transport":"non-http transport requested" }, "status": { "requesting": "requesting"