diff options
Diffstat (limited to 'lib/caldav/xhr.js')
-rw-r--r-- | lib/caldav/xhr.js | 65 |
1 files changed, 38 insertions, 27 deletions
diff --git a/lib/caldav/xhr.js b/lib/caldav/xhr.js index e88e789..6c8351f 100644 --- a/lib/caldav/xhr.js +++ b/lib/caldav/xhr.js @@ -50,6 +50,7 @@ user: null, password: null, url: null, + streaming: true, headers: {}, data: null, @@ -85,12 +86,7 @@ } }, - /** - * Sends request to server. - * - * @param {Function} callback success/failure handler. - */ - send: function send(callback) { + _buildXHR: function(callback) { var header; if (typeof(callback) === 'undefined') { @@ -116,7 +112,11 @@ } var useMozChunkedText = false; - if (this.globalXhrOptions && this.globalXhrOptions.useMozChunkedText) { + if ( + this.streaming && + this.globalXhrOptions && + this.globalXhrOptions.useMozChunkedText + ) { useMozChunkedText = true; this.xhr.responseType = 'moz-chunked-text'; } @@ -131,24 +131,26 @@ var hasProgressEvents = false; // check for progress event support. - if ('onprogress' in this.xhr) { - hasProgressEvents = true; - var last = 0; - - if (useMozChunkedText) { - this.xhr.onprogress = (function onChunkedProgress(event) { - if (this.ondata) { - this.ondata(this.xhr.responseText); - } - }.bind(this)); - } else { - this.xhr.onprogress = (function onProgress(event) { - var chunk = this.xhr.responseText.substr(last, event.loaded); - last = event.loaded; - if (this.ondata) { - this.ondata(chunk); - } - }.bind(this)); + if (this.streaming) { + if ('onprogress' in this.xhr) { + hasProgressEvents = true; + var last = 0; + + if (useMozChunkedText) { + this.xhr.onprogress = (function onChunkedProgress(event) { + if (this.ondata) { + this.ondata(this.xhr.responseText); + } + }.bind(this)); + } else { + this.xhr.onprogress = (function onProgress(event) { + var chunk = this.xhr.responseText.substr(last, event.loaded); + last = event.loaded; + if (this.ondata) { + this.ondata(chunk); + } + }.bind(this)); + } } } @@ -171,9 +173,18 @@ }.bind(this)); this.waiting = true; - this.xhr.send(this._serialize()); - return this.xhr; + }, + + /** + * Sends request to server. + * + * @param {Function} callback success/failure handler. + */ + send: function send(callback) { + var xhr = this._buildXHR(callback); + xhr.send(this._serialize()); + return xhr; } }; |