@@ -126,9 +126,7 @@ function fromByteArray (uint8) {
126
126
127
127
// go through the array every three bytes, we'll deal with trailing stuff later
128
128
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
129
- parts.push(encodeChunk(
130
- uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
131
- ))
129
+ parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
132
130
}
133
131
134
132
// pad the end with zeros, but make sure to not forget the extra bytes
@@ -3097,6 +3095,7 @@ function validateParams (params) {
3097
3095
}
3098
3096
3099
3097
},{"http":17,"url":37}],8:[function(require,module,exports){
3098
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
3100
3099
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
3101
3100
var e, m
3102
3101
var eLen = (nBytes * 8) - mLen - 1
@@ -6639,6 +6638,8 @@ var ClientRequest = module.exports = function (opts) {
6639
6638
}
6640
6639
self._mode = decideMode(preferBinary, useFetch)
6641
6640
self._fetchTimer = null
6641
+ self._socketTimeout = null
6642
+ self._socketTimer = null
6642
6643
6643
6644
self.on('finish', function () {
6644
6645
self._onFinish()
@@ -6681,6 +6682,10 @@ ClientRequest.prototype._onFinish = function () {
6681
6682
return
6682
6683
var opts = self._opts
6683
6684
6685
+ if ('timeout' in opts && opts.timeout !== 0) {
6686
+ self.setTimeout(opts.timeout)
6687
+ }
6688
+
6684
6689
var headersObj = self._headers
6685
6690
var body = null
6686
6691
if (opts.method !== 'GET' && opts.method !== 'HEAD') {
@@ -6728,9 +6733,10 @@ ClientRequest.prototype._onFinish = function () {
6728
6733
signal: signal
6729
6734
}).then(function (response) {
6730
6735
self._fetchResponse = response
6736
+ self._resetTimers(false)
6731
6737
self._connect()
6732
6738
}, function (reason) {
6733
- global.clearTimeout( self._fetchTimer )
6739
+ self._resetTimers(true )
6734
6740
if (!self._destroyed)
6735
6741
self.emit('error', reason)
6736
6742
})
@@ -6786,6 +6792,7 @@ ClientRequest.prototype._onFinish = function () {
6786
6792
xhr.onerror = function () {
6787
6793
if (self._destroyed)
6788
6794
return
6795
+ self._resetTimers(true)
6789
6796
self.emit('error', new Error('XHR error'))
6790
6797
}
6791
6798
@@ -6817,13 +6824,15 @@ function statusValid (xhr) {
6817
6824
ClientRequest.prototype._onXHRProgress = function () {
6818
6825
var self = this
6819
6826
6827
+ self._resetTimers(false)
6828
+
6820
6829
if (!statusValid(self._xhr) || self._destroyed)
6821
6830
return
6822
6831
6823
6832
if (!self._response)
6824
6833
self._connect()
6825
6834
6826
- self._response._onXHRProgress()
6835
+ self._response._onXHRProgress(self._resetTimers.bind(self) )
6827
6836
}
6828
6837
6829
6838
ClientRequest.prototype._connect = function () {
@@ -6832,7 +6841,7 @@ ClientRequest.prototype._connect = function () {
6832
6841
if (self._destroyed)
6833
6842
return
6834
6843
6835
- self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode, self._fetchTimer )
6844
+ self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode, self._resetTimers.bind(self) )
6836
6845
self._response.on('error', function(err) {
6837
6846
self.emit('error', err)
6838
6847
})
@@ -6847,16 +6856,35 @@ ClientRequest.prototype._write = function (chunk, encoding, cb) {
6847
6856
cb()
6848
6857
}
6849
6858
6850
- ClientRequest.prototype.abort = ClientRequest.prototype.destroy = function () {
6859
+ ClientRequest.prototype._resetTimers = function (done) {
6860
+ var self = this
6861
+
6862
+ global.clearTimeout(self._socketTimer)
6863
+ self._socketTimer = null
6864
+
6865
+ if (done) {
6866
+ global.clearTimeout(self._fetchTimer)
6867
+ self._fetchTimer = null
6868
+ } else if (self._socketTimeout) {
6869
+ self._socketTimer = global.setTimeout(function () {
6870
+ self.emit('timeout')
6871
+ }, self._socketTimeout)
6872
+ }
6873
+ }
6874
+
6875
+ ClientRequest.prototype.abort = ClientRequest.prototype.destroy = function (err) {
6851
6876
var self = this
6852
6877
self._destroyed = true
6853
- global.clearTimeout( self._fetchTimer )
6878
+ self._resetTimers(true )
6854
6879
if (self._response)
6855
6880
self._response._destroyed = true
6856
6881
if (self._xhr)
6857
6882
self._xhr.abort()
6858
6883
else if (self._fetchAbortController)
6859
6884
self._fetchAbortController.abort()
6885
+
6886
+ if (err)
6887
+ self.emit('error', err)
6860
6888
}
6861
6889
6862
6890
ClientRequest.prototype.end = function (data, encoding, cb) {
@@ -6869,8 +6897,17 @@ ClientRequest.prototype.end = function (data, encoding, cb) {
6869
6897
stream.Writable.prototype.end.call(self, data, encoding, cb)
6870
6898
}
6871
6899
6900
+ ClientRequest.prototype.setTimeout = function (timeout, cb) {
6901
+ var self = this
6902
+
6903
+ if (cb)
6904
+ self.once('timeout', cb)
6905
+
6906
+ self._socketTimeout = timeout
6907
+ self._resetTimers(false)
6908
+ }
6909
+
6872
6910
ClientRequest.prototype.flushHeaders = function () {}
6873
- ClientRequest.prototype.setTimeout = function () {}
6874
6911
ClientRequest.prototype.setNoDelay = function () {}
6875
6912
ClientRequest.prototype.setSocketKeepAlive = function () {}
6876
6913
@@ -6913,7 +6950,7 @@ var rStates = exports.readyStates = {
6913
6950
DONE: 4
6914
6951
}
6915
6952
6916
- var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode, fetchTimer ) {
6953
+ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode, resetTimers ) {
6917
6954
var self = this
6918
6955
stream.Readable.call(self)
6919
6956
@@ -6946,6 +6983,7 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode, f
6946
6983
if (capability.writableStream) {
6947
6984
var writable = new WritableStream({
6948
6985
write: function (chunk) {
6986
+ resetTimers(false)
6949
6987
return new Promise(function (resolve, reject) {
6950
6988
if (self._destroyed) {
6951
6989
reject()
@@ -6957,19 +6995,20 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode, f
6957
6995
})
6958
6996
},
6959
6997
close: function () {
6960
- global.clearTimeout(fetchTimer )
6998
+ resetTimers(true )
6961
6999
if (!self._destroyed)
6962
7000
self.push(null)
6963
7001
},
6964
7002
abort: function (err) {
7003
+ resetTimers(true)
6965
7004
if (!self._destroyed)
6966
7005
self.emit('error', err)
6967
7006
}
6968
7007
})
6969
7008
6970
7009
try {
6971
7010
response.body.pipeTo(writable).catch(function (err) {
6972
- global.clearTimeout(fetchTimer )
7011
+ resetTimers(true )
6973
7012
if (!self._destroyed)
6974
7013
self.emit('error', err)
6975
7014
})
@@ -6982,15 +7021,15 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode, f
6982
7021
reader.read().then(function (result) {
6983
7022
if (self._destroyed)
6984
7023
return
7024
+ resetTimers(result.done)
6985
7025
if (result.done) {
6986
- global.clearTimeout(fetchTimer)
6987
7026
self.push(null)
6988
7027
return
6989
7028
}
6990
7029
self.push(Buffer.from(result.value))
6991
7030
read()
6992
7031
}).catch(function (err) {
6993
- global.clearTimeout(fetchTimer )
7032
+ resetTimers(true )
6994
7033
if (!self._destroyed)
6995
7034
self.emit('error', err)
6996
7035
})
@@ -7049,7 +7088,7 @@ IncomingMessage.prototype._read = function () {
7049
7088
}
7050
7089
}
7051
7090
7052
- IncomingMessage.prototype._onXHRProgress = function () {
7091
+ IncomingMessage.prototype._onXHRProgress = function (resetTimers ) {
7053
7092
var self = this
7054
7093
7055
7094
var xhr = self._xhr
@@ -7096,6 +7135,7 @@ IncomingMessage.prototype._onXHRProgress = function () {
7096
7135
}
7097
7136
}
7098
7137
reader.onload = function () {
7138
+ resetTimers(true)
7099
7139
self.push(null)
7100
7140
}
7101
7141
// reader.onerror = ??? // TODO: this
@@ -7105,6 +7145,7 @@ IncomingMessage.prototype._onXHRProgress = function () {
7105
7145
7106
7146
// The ms-stream case handles end separately in reader.onload()
7107
7147
if (self._xhr.readyState === rStates.DONE && self._mode !== 'ms-stream') {
7148
+ resetTimers(true)
7108
7149
self.push(null)
7109
7150
}
7110
7151
}
@@ -21936,7 +21977,7 @@ module.exports = {
21936
21977
data: null,
21937
21978
valid: false,
21938
21979
after: function (err) {
21939
- expect(err.message).toBe("Invalid .validate call - schema must be an string or object but null was passed!");
21980
+ expect(err.message).toBe("Invalid .validate call - schema must be a string or object but null was passed!");
21940
21981
}
21941
21982
}
21942
21983
]
0 commit comments