This is an automated email from the ASF dual-hosted git repository.

rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-package-kafka.git


The following commit(s) were added to refs/heads/master by this push:
     new d1ce6d4  Handle URL params gently (#370)
d1ce6d4 is described below

commit d1ce6d4b2472aa17978d288173f2d0a3692cf258
Author: Nikolay <[email protected]>
AuthorDate: Fri Jun 19 15:31:22 2020 +0300

    Handle URL params gently (#370)
    
    Previously url variable has strictly provided "https" protocol,
    which totally broke feed if "https" was provided in endpoint variable.
    Add new function based on regex to handle both types with or
    without protocol.
---
 action/lib/common.js | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/action/lib/common.js b/action/lib/common.js
index e154d13..a09bc4e 100644
--- a/action/lib/common.js
+++ b/action/lib/common.js
@@ -26,14 +26,21 @@ function triggerComponents(triggerName) {
     };
 }
 
+function addHTTPS(url) {
+    if (!/^https?\:\/\//.test(url)) {
+        url = "https://"; + url;
+    }
+    return url;
+}
+
 function getTriggerURL(endpoint, triggerName) {
-    var massagedAPIHost = endpoint.replace(/https?:\/\/(.*)/, "$1");
+    var apiHost = addHTTPS(endpoint);
 
     var components = triggerComponents(triggerName);
     var namespace = components.namespace;
     var trigger = components.triggerName;
 
-    var url = 
`https://${massagedAPIHost}/api/v1/namespaces/${encodeURIComponent(namespace)}/triggers/${encodeURIComponent(trigger)}`;
+    var url = 
`${apiHost}/api/v1/namespaces/${encodeURIComponent(namespace)}/triggers/${encodeURIComponent(trigger)}`;
 
     return url;
 }
@@ -98,7 +105,9 @@ function massageParamsForWeb(rawParams) {
 }
 
 function getWebActionURL(endpoint, actionName) {
-    return 
`https://${endpoint}/api/v1/web/whisk.system/messagingWeb/${actionName}.http`;
+    var apiHost = addHTTPS(endpoint);
+
+    return `${apiHost}/api/v1/web/whisk.system/messagingWeb/${actionName}`;
 }
 
 function createTrigger(endpoint, params, actionName) {

Reply via email to