diff options
Diffstat (limited to 'lib/caldav')
-rw-r--r-- | lib/caldav/xhr.js | 27 |
1 files changed, 23 insertions, 4 deletions
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 @@ -67,6 +67,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. * * @param {Function} callback success/failure handler. @@ -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) { |