Skip to content

Commit

Permalink
fix/hack to send progress datas total, loaded and lengthComputable
Browse files Browse the repository at this point in the history
  • Loading branch information
ouhouhsami committed Aug 14, 2014
1 parent e23b639 commit 3e72d57
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/xmlhttprequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,15 @@
_properties.responseHeaders = response.headers;
contentLength = response.headers['content-length'] || contentLength;
bufferLength = parseInt(contentLength, 10);
this.lengthComputable = false;
if(bufferLength !== 0){
this.total = bufferLength;
this.loaded = 0;
this.lengthComputable = true;
}
_properties.responseBuffer = new Buffer(bufferLength);
_readyStateChange.call(this, XMLHttpRequest.LOADING);
var that = this;
response.addListener('data', function(chunk) {
var buffer;
if (bufferLength === 0) {
Expand All @@ -335,6 +342,7 @@
}
chunk.copy(this._properties.responseBuffer, byteOffset);
byteOffset += chunk.length;
that.loaded = byteOffset;
_readyStateChange.call(this, XMLHttpRequest.LOADING);
}.bind(this));
response.addListener('end', function() {
Expand All @@ -347,7 +355,8 @@
var loadStartEvent = new ProgressEvent('loadstart');
this.dispatchEvent(loadStartEvent);
stream.on('data', function() {
var progressEvent = new ProgressEvent('progress');
var progress = {lengthComputable: this.lengthComputable, total: this.total, loaded: this.loaded};
var progressEvent = new ProgressEvent('progress', progress);
this.dispatchEvent(progressEvent);
}.bind(this));
stream.on('end', function() {
Expand Down Expand Up @@ -437,7 +446,7 @@

proto.setRequestHeader = function setRequestHeader(header, value) {
if (this.readyState === XMLHttpRequest.UNSENT) {
throw new Error(''); // todo
throw new Error(''); // todo
}
this._properties.requestHeaders[header] = value;
};
Expand Down

0 comments on commit 3e72d57

Please sign in to comment.