@@ -676,6 +676,17 @@ Request.prototype.end = function(fn){
676
676
return this . _end ( ) ;
677
677
} ;
678
678
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
+
679
690
Request . prototype . _end = function ( ) {
680
691
if ( this . _aborted ) return this . callback ( Error ( "The request has been aborted even before .end() was called" ) ) ;
681
692
@@ -710,10 +721,12 @@ Request.prototype._end = function() {
710
721
// progress
711
722
const handleProgress = ( direction , e ) => {
712
723
713
- clearTimeout ( self . _uploadTimeoutTimer ) ;
714
724
if ( e . total > 0 ) {
715
725
e . percent = e . loaded / e . total * 100 ;
726
+ } else if ( e . total = 100 ) {
727
+ clearTimeout ( self . _uploadTimeoutTimer ) ;
716
728
}
729
+
717
730
e . direction = direction ;
718
731
self . emit ( 'progress' , e ) ;
719
732
} ;
@@ -731,12 +744,7 @@ Request.prototype._end = function() {
731
744
}
732
745
733
746
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 ( ) ;
740
748
}
741
749
742
750
// initiate request
0 commit comments