Skip to content

Commit 03e5efa

Browse files
committed
change after review
1 parent 650b521 commit 03e5efa

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

lib/client.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,17 @@ Request.prototype.end = function(fn){
676676
return this._end();
677677
};
678678

679+
Request.prototype._setUploadTimeout = function () {
680+
const self = this;
681+
682+
// upload timeout it's wokrs only if deadline timeout is off
683+
if (this._uploadTimeout && !this._uploadTimeoutTimer) {
684+
this._uploadTimeoutTimer = setTimeout(() => {
685+
self._timeoutError('Upload timeout of ', self._uploadTimeout, 'ETIMEDOUT');
686+
}, this._uploadTimeout);
687+
}
688+
};
689+
679690
Request.prototype._end = function() {
680691
if (this._aborted) return this.callback(Error("The request has been aborted even before .end() was called"));
681692

@@ -710,10 +721,12 @@ Request.prototype._end = function() {
710721
// progress
711722
const handleProgress = (direction, e) => {
712723

713-
clearTimeout(self._uploadTimeoutTimer);
714724
if (e.total > 0) {
715725
e.percent = e.loaded / e.total * 100;
726+
} else if(e.total = 100){
727+
clearTimeout(self._uploadTimeoutTimer);
716728
}
729+
717730
e.direction = direction;
718731
self.emit('progress', e);
719732
};
@@ -731,12 +744,7 @@ Request.prototype._end = function() {
731744
}
732745

733746
if(xhr.upload){
734-
// upload timeout it's wokrs only if deadline timeout is off
735-
if (this._uploadTimeout && !this._uploadTimeoutTimer) {
736-
this._uploadTimeoutTimer = setTimeout(() => {
737-
self._timeoutError('Upload timeout of ', self._uploadTimeout, 'ETIMEDOUT');
738-
}, this._uploadTimeout);
739-
}
747+
this._setUploadTimeout();
740748
}
741749

742750
// initiate request

0 commit comments

Comments
 (0)