瀏覽代碼

HUE-8888 [knox] Enable XHR URL rewrite only if Knox is there

Romain 6 年之前
父節點
當前提交
2ed6fae0e6
共有 1 個文件被更改,包括 15 次插入13 次删除
  1. 15 13
      desktop/core/src/desktop/templates/common_header_footer_components.mako

+ 15 - 13
desktop/core/src/desktop/templates/common_header_footer_components.mako

@@ -86,20 +86,22 @@ from metadata.conf import has_optimizer, OPTIMIZER
       }
       }
     }
     }
 
 
-
-    var xhrOpen = XMLHttpRequest.prototype.open;
-    XMLHttpRequest.prototype.open = function () {
-      if (arguments[1].indexOf(window.HUE_BASE_URL) < 0) {
-        var index = arguments[1].indexOf(window.location.host);
-        if (index >= 0 && window.HUE_BASE_URL.length) { //Host is present in the url when using an html form.
-          index += window.location.host.length;
-            arguments[1] = arguments[1].substring(0, index) + window.HUE_BASE_URL + arguments[1].substring(index);
-        } else {
-          arguments[1] = window.HUE_BASE_URL + arguments[1];
+    // Enable XHR URL rewrite if Knox is there
+    if (window.HUE_BASE_URL && window.HUE_BASE_URL.length) {
+      var xhrOpen = XMLHttpRequest.prototype.open;
+      XMLHttpRequest.prototype.open = function () {
+        if (arguments[1].indexOf(window.HUE_BASE_URL) < 0) {
+          var index = arguments[1].indexOf(window.location.host);
+          if (index >= 0 && window.HUE_BASE_URL.length) { // Host is present in the URL when using an HTML form
+            index += window.location.host.length;
+              arguments[1] = arguments[1].substring(0, index) + window.HUE_BASE_URL + arguments[1].substring(index);
+          } else {
+            arguments[1] = window.HUE_BASE_URL + arguments[1];
+          }
         }
         }
-      }
-      return xhrOpen.apply(this, arguments);
-    };
+        return xhrOpen.apply(this, arguments);
+      };
+    }
     var xhrSend = XMLHttpRequest.prototype.send;
     var xhrSend = XMLHttpRequest.prototype.send;
     XMLHttpRequest.prototype.send = function (data) {
     XMLHttpRequest.prototype.send = function (data) {
       // Add CSRF Token to all XHR Requests
       // Add CSRF Token to all XHR Requests