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 --- caldav.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'caldav.js') diff --git a/caldav.js b/caldav.js index 6975f65..7f3d367 100644 --- a/caldav.js +++ b/caldav.js @@ -2068,7 +2068,6 @@ function write (chunk) { } 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 @@ -2083,6 +2082,12 @@ function write (chunk) { )); } + 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]); @@ -2096,13 +2101,20 @@ function write (chunk) { 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