diff options
author | James Lal <james@lightsofapollo.com> | 2013-01-09 11:21:04 +0100 |
---|---|---|
committer | James Lal <james@lightsofapollo.com> | 2013-01-09 11:21:04 +0100 |
commit | ff00ab9fcaf0f791b1873ca1cd4d80e8a6dd6cda (patch) | |
tree | bf3539c61581137225f2e848f289271bd7fbb1a7 /lib/caldav/xhr.js | |
parent | 843b96d1822a28cee8eed1776aa37b6322432249 (diff) | |
download | jsCalDAV-ff00ab9fcaf0f791b1873ca1cd4d80e8a6dd6cda.tar.gz |
utilize moz-chunked-text when given the option
Diffstat (limited to 'lib/caldav/xhr.js')
-rw-r--r-- | lib/caldav/xhr.js | 28 |
1 files changed, 20 insertions, 8 deletions
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() { |