braid-http 1.3.55 → 1.3.57

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.
@@ -947,12 +947,23 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
947
947
  if (!try_deleting.has(request)) {
948
948
  try_deleting.add(request)
949
949
  try {
950
+ var mux_was_done = await promise_done(mux_promise)
951
+
950
952
  var r = await braid_fetch(`${origin}/.well-known/multiplexer/${multiplexer}/${request}`, {
951
953
  method: 'DELETE',
952
954
  headers: { 'Multiplex-Version': multiplex_version },
953
955
  retry: true
954
956
  })
955
957
 
958
+ // if we know the multiplexer was created,
959
+ // but it isn't there now,
960
+ // and our client doesn't realize it,
961
+ // then shut it down ourselves
962
+ if (r.status === 404 && r.headers.get('Bad-Multiplexer')
963
+ && mux_was_done && !mux_error) {
964
+ cleanup_multiplexer(new Error('multiplexer detected to be closed'))
965
+ }
966
+
956
967
  if (!r.ok) throw new Error('status not ok: ' + r.status)
957
968
  if (r.headers.get('Multiplex-Version') !== multiplex_version)
958
969
  throw new Error('wrong multiplex version: '
@@ -974,7 +985,8 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
974
985
  signal: mux_aborter.signal,
975
986
  method: 'MULTIPLEX',
976
987
  headers: {'Multiplex-Version': multiplex_version},
977
- retry: true
988
+ retry: true,
989
+ multiplex: false
978
990
  })
979
991
  if (r.status === 409) {
980
992
  var e = await r.json()
@@ -991,7 +1003,8 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
991
1003
  {method: 'POST',
992
1004
  signal: mux_aborter.signal,
993
1005
  headers: {'Multiplex-Version': multiplex_version},
994
- retry: true})
1006
+ retry: true,
1007
+ multiplex: false})
995
1008
  if (r.status === 409) {
996
1009
  var e = await r.json()
997
1010
  if (e.error === 'Multiplexer already exists')
@@ -221,6 +221,12 @@ function parse_content_range (range_string) {
221
221
  }
222
222
 
223
223
  function braidify (req, res, next) {
224
+ if (typeof req === 'function') {
225
+ var handler = req
226
+ return (req, res, next) =>
227
+ braidify(req, res, () => handler(req, res, next))
228
+ }
229
+
224
230
  // console.log('\n## Braidifying', req.method, req.url, req.headers.peer)
225
231
 
226
232
  // First, declare that we support Patches and JSON ranges.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "1.3.55",
3
+ "version": "1.3.57",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/server.js"