aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-07-23 22:37:40 -0700
committerJames Lal <james@lightsofapollo.com>2012-07-23 22:37:40 -0700
commit585956e08bb7afaa3001684e7a65bf462d7acaaa (patch)
treef6b5607cf116acf437e2d5da6e8e80e8d0c2dd5c /lib
parent2a138899fd6cb44256f7b31765bbe8e52508df1a (diff)
downloadjsCalDAV-585956e08bb7afaa3001684e7a65bf462d7acaaa.tar.gz
xhr fixes for firefox
Diffstat (limited to 'lib')
-rw-r--r--lib/caldav/xhr.js27
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) {