From ff00ab9fcaf0f791b1873ca1cd4d80e8a6dd6cda Mon Sep 17 00:00:00 2001 From: James Lal Date: Wed, 9 Jan 2013 11:21:04 +0100 Subject: utilize moz-chunked-text when given the option --- lib/caldav/xhr.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/caldav/xhr.js b/lib/caldav/xhr.js index 230f656..d49186b 100644 --- a/lib/caldav/xhr.js +++ b/lib/caldav/xhr.js @@ -86,7 +86,6 @@ } else { xhr = new this.xhrClass(); } - // This hack is in place due to some platform // bug in gecko when using mozSystem xhr // the credentials only seem to work as expected @@ -101,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]); @@ -114,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() { -- cgit