braid-http 1.3.4 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -141,7 +141,7 @@ if (is_nodejs) {
141
141
  }
142
142
 
143
143
  async function braid_fetch (url, params = {}) {
144
- params = {...params} // Copy params, because we'll mutate it
144
+ params = deep_copy(params) // Copy params, because we'll mutate it
145
145
 
146
146
  // Initialize the headers object
147
147
  if (!params.headers)
@@ -234,6 +234,7 @@ async function braid_fetch (url, params = {}) {
234
234
  )
235
235
 
236
236
  var waitTime = 10
237
+ var waitedTime = 0
237
238
  var res = null
238
239
  var subscription_cb = null
239
240
  var subscription_error = null
@@ -251,8 +252,15 @@ async function braid_fetch (url, params = {}) {
251
252
 
252
253
  underlying_aborter.abort()
253
254
 
255
+ if (params.retry.timeout && waitedTime + waitTime > params.retry.timeout) {
256
+ e = new Error('Timeout Error')
257
+ subscription_error?.(e)
258
+ return fail(e)
259
+ }
260
+
254
261
  console.log(`retrying in ${waitTime}ms: ${url} after error: ${e}`)
255
262
  setTimeout(connect, waitTime)
263
+ waitedTime += waitTime
256
264
  waitTime = Math.min(waitTime * 2, 3000)
257
265
  }
258
266
 
@@ -411,6 +419,7 @@ async function braid_fetch (url, params = {}) {
411
419
 
412
420
  params?.retry?.onRes?.(res)
413
421
  waitTime = 10
422
+ waitedTime = 0
414
423
  } catch (e) { on_error(e) }
415
424
  }
416
425
  })
@@ -804,6 +813,13 @@ function get_binary_length(x) {
804
813
  x instanceof Blob ? x.size : undefined
805
814
  }
806
815
 
816
+ function deep_copy(x) {
817
+ if (x === null || typeof x !== 'object') return x
818
+ if (Array.isArray(x)) return x.map(x => deep_copy(x))
819
+ if (Object.prototype.toString.call(x) === '[object Object]') return Object.fromEntries(Object.entries(x).map(([k, x]) => [k, deep_copy(x)]))
820
+ return x
821
+ }
822
+
807
823
  // ****************************
808
824
  // Exports
809
825
  // ****************************
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/server.js"