From 585956e08bb7afaa3001684e7a65bf462d7acaaa Mon Sep 17 00:00:00 2001 From: James Lal Date: Mon, 23 Jul 2012 22:37:40 -0700 Subject: xhr fixes for firefox --- lib/caldav/xhr.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/caldav/xhr.js b/lib/caldav/xhr.js index ac26865..ff4bdd3 100644 --- a/lib/caldav/xhr.js +++ b/lib/caldav/xhr.js @@ -66,6 +66,18 @@ } }, + /** + * @param {String} user basic auth user. + * @param {String} password basic auth pass. + * @return {String} basic auth token. + */ + _credentials: function(user, pass) { + // this code should never run in nodejs. + return 'Basic ' + window.btoa( + user + ':' + pass + ); + }, + /** * Sends request to server. * @@ -86,10 +98,18 @@ this.xhr = xhr; - if (Xhr.authHack) { - xhr.open(this.method, this.url, this.async); - } else { + // This hack is in place due to some platform + // bug in gecko when using mozSystem xhr + // the credentials only seem to work as expected + // when constructing them manually. + if (!this.globalXhrOptions || !this.globalXhrOptions.mozSystem) { xhr.open(this.method, this.url, this.async, this.user, this.password); + } else { + xhr.open(this.method, this.url, this.async); + xhr.setRequestHeader('Authorization', this._credentials( + this.user, + this.password + )); } for (header in this.headers) { @@ -98,7 +118,6 @@ } } - xhr.onreadystatechange = function onReadyStateChange() { var data; if (xhr.readyState === 4) { -- cgit