diff --git a/lib/client.js b/lib/client.js index 9109adba0..5f8c8e7ec 100644 --- a/lib/client.js +++ b/lib/client.js @@ -676,6 +676,17 @@ Request.prototype.end = function(fn){ return this._end(); }; +Request.prototype._setUploadTimeout = function () { + const self = this; + + // upload timeout it's wokrs only if deadline timeout is off + if (this._uploadTimeout && !this._uploadTimeoutTimer) { + this._uploadTimeoutTimer = setTimeout(() => { + self._timeoutError('Upload timeout of ', self._uploadTimeout, 'ETIMEDOUT'); + }, this._uploadTimeout); + } +}; + Request.prototype._end = function() { if (this._aborted) return this.callback(Error("The request has been aborted even before .end() was called")); @@ -710,10 +721,12 @@ Request.prototype._end = function() { // progress const handleProgress = (direction, e) => { - clearTimeout(self._uploadTimeoutTimer); if (e.total > 0) { e.percent = e.loaded / e.total * 100; + } else if(e.total = 100){ + clearTimeout(self._uploadTimeoutTimer); } + e.direction = direction; self.emit('progress', e); }; @@ -731,12 +744,7 @@ Request.prototype._end = function() { } if(xhr.upload){ - // upload timeout it's wokrs only if deadline timeout is off - if (this._uploadTimeout && !this._uploadTimeoutTimer) { - this._uploadTimeoutTimer = setTimeout(() => { - self._timeoutError('Upload timeout of ', self._uploadTimeout, 'ETIMEDOUT'); - }, this._uploadTimeout); - } + this._setUploadTimeout(); } // initiate request