diff --git a/catalog.tag b/catalog.tag
index fd6d686..a5c1a6f 100644
--- a/catalog.tag
+++ b/catalog.tag
@@ -41,7 +41,7 @@
registryUI.catalog.instance = this;
this.mixin('rg.router');
registryUI.catalog.display = function () {
- var oReq = new XMLHttpRequest();
+ var oReq = new Http();
registryUI.catalog.createSnackbar = function (msg) {
var snackbar = document.querySelector('#error-snackbar');
registryUI.catalog.error = msg;
@@ -72,7 +72,6 @@
registryUI.catalog.instance.update();
});
oReq.open('GET', registryUI.url() + '/v2/_catalog');
- oReq.withCredentials = true;
oReq.send();
};
this.on('updated', function () {
diff --git a/http.js b/http.js
new file mode 100644
index 0000000..edc3a69
--- /dev/null
+++ b/http.js
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2016 Jones Magloire @Joxit
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+function Http() {
+ this.oReq = new XMLHttpRequest();
+ this._events = {};
+}
+
+Http.prototype.addEventListener = function(e, f) {
+ this._events[e] = f;
+ switch (e) {
+ case 'loadend':
+ {
+ this.oReq.addEventListener('loadend', function() {
+ if (this.status == 401) {
+ var req = new XMLHttpRequest();
+ for (key in this.http._events) {
+ req.addEventListener(key, this.http._events[key]);
+ }
+ req.withCredentials = true;
+ req.open(this.http._method, this.http._url);
+ req.send();
+ } else {
+ f.bind(this.oReq);
+ }
+ });
+ break;
+ }
+ default:
+ {
+ this.oReq.addEventListener(e, function() {
+ f.bind(this.oReq);
+ });
+ break;
+ }
+ }
+};
+
+Http.prototype.open = function(m, u) {
+ this._method = m;
+ this._url = u;
+ this.oReq.open(m, u);
+};
+
+Http.prototype.send = function() {
+ this.oReq.http = this;
+ this.oReq.send();
+};
diff --git a/index.html b/index.html
index 3c24225..5388065 100644
--- a/index.html
+++ b/index.html
@@ -67,6 +67,7 @@
+