aboutsummaryrefslogtreecommitdiffstats
path: root/lib/caldav
diff options
context:
space:
mode:
Diffstat (limited to 'lib/caldav')
-rw-r--r--lib/caldav/request/abstract.js3
-rw-r--r--lib/caldav/request/errors.js8
-rw-r--r--lib/caldav/xhr.js41
3 files changed, 27 insertions, 25 deletions
diff --git a/lib/caldav/request/abstract.js b/lib/caldav/request/abstract.js
index eb6297b..7116217 100644
--- a/lib/caldav/request/abstract.js
+++ b/lib/caldav/request/abstract.js
@@ -65,8 +65,7 @@
};
// in the future we may stream data somehow
- req.send(function xhrResult() {
- var xhr = req.xhr;
+ req.send(function xhrResult(err, xhr) {
if (xhr.status > 199 && xhr.status < 300) {
// success
self.sax.close();
diff --git a/lib/caldav/request/errors.js b/lib/caldav/request/errors.js
index c3c166e..700cfba 100644
--- a/lib/caldav/request/errors.js
+++ b/lib/caldav/request/errors.js
@@ -16,26 +16,26 @@
default:
message = this.code;
}
-
Error.call(this, message);
}
+
CaldavHttpError.prototype = {
__proto__: Error.prototype,
constructor: CaldavHttpError
}
-
+
// Unauthenticated error for
// Google Calendar
function UnauthenticatedError() {
var message = "Wrong username or/and password";
Error.call(this, message);
}
-
+
UnauthenticatedError.prototype = {
__proto__: Error.prototype,
constructor: UnauthenticatedError
}
-
+
module.exports = {
CaldavHttpError: CaldavHttpError,
UnauthenticatedError: UnauthenticatedError
diff --git a/lib/caldav/xhr.js b/lib/caldav/xhr.js
index abeae79..d49186b 100644
--- a/lib/caldav/xhr.js
+++ b/lib/caldav/xhr.js
@@ -58,15 +58,6 @@
},
/**
- * Aborts request if its in progress.
- */
- abort: function abort() {
- if (this.xhr) {
- this.xhr.abort();
- }
- },
-
- /**
* @param {String} user basic auth user.
* @param {String} password basic auth pass.
* @return {String} basic auth token.
@@ -95,9 +86,6 @@
} else {
xhr = new this.xhrClass();
}
-
- this.xhr = xhr;
-
// This hack is in place due to some platform
// bug in gecko when using mozSystem xhr
// the credentials only seem to work as expected
@@ -112,6 +100,12 @@
));
}
+ var useMozChunkedText = false;
+ if (this.globalXhrOptions && this.globalXhrOptions.useMozChunkedText) {
+ useMozChunkedText = true;
+ xhr.responseType = 'moz-chunked-text';
+ }
+
for (header in this.headers) {
if (Object.hasOwnProperty.call(this.headers, header)) {
xhr.setRequestHeader(header, this.headers[header]);
@@ -125,13 +119,20 @@
if ('onprogress' in xhr) {
hasProgressEvents = true;
var last = 0;
- xhr.onprogress = function onProgress(event) {
- var chunk = xhr.responseText.substr(last, event.loaded);
- last = event.loaded;
- if (this.ondata) {
- this.ondata(chunk);
- }
- }.bind(this);
+
+ if (useMozChunkedText) {
+ xhr.onprogress = function onChunkedProgress(event) {
+ this.ondata(xhr.responseText);
+ }.bind(this);
+ } else {
+ xhr.onprogress = function onProgress(event) {
+ var chunk = xhr.responseText.substr(last, event.loaded);
+ last = event.loaded;
+ if (this.ondata) {
+ this.ondata(chunk);
+ }
+ }.bind(this);
+ }
}
xhr.onreadystatechange = function onReadyStateChange() {
@@ -154,6 +155,8 @@
this.waiting = true;
xhr.send(this._seralize());
+
+ return xhr;
}
};