diff options
author | James Lal <james@lightsofapollo.com> | 2013-01-07 08:26:13 +0100 |
---|---|---|
committer | James Lal <james@lightsofapollo.com> | 2013-01-07 08:38:32 +0100 |
commit | d64a1c54d6098596af1ed68272c78975ec56d0b7 (patch) | |
tree | 13a53efd31ff216fd89f7bd243ee726139824a40 /lib/caldav/xhr.js | |
parent | 0b6e8afda0bc88fdfe0a64a15abfe537b5569bf7 (diff) | |
download | jsCalDAV-d64a1c54d6098596af1ed68272c78975ec56d0b7.tar.gz |
support for chunked responses
Diffstat (limited to 'lib/caldav/xhr.js')
-rw-r--r-- | lib/caldav/xhr.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/caldav/xhr.js b/lib/caldav/xhr.js index 4ed7ec6..abeae79 100644 --- a/lib/caldav/xhr.js +++ b/lib/caldav/xhr.js @@ -118,10 +118,35 @@ } } + + var hasProgressEvents = false; + + // check for progress event support. + 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); + } + xhr.onreadystatechange = function onReadyStateChange() { var data; if (xhr.readyState === 4) { data = xhr.responseText; + + // emulate progress events for node... + // this really lame we should probably just + // use a real http request for node but this + // will let us do some testing via node for now. + if (!hasProgressEvents && this.ondata) { + this.ondata(data); + } + this.waiting = false; callback(null, xhr); } |