braid-http 1.3.48 → 1.3.49

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.
@@ -919,13 +919,13 @@ async function multiplex_fetch(url, params, mux_params) {
919
919
  // fallback to normal fetch if multiplexed connection fails
920
920
  console.error(`Could not establish multiplexer.\n`
921
921
  + `Got error: ${e}.\nFalling back to normal connection.`)
922
- return cleanup(e, true)
922
+ cleanup(e, true)
923
+ return false
923
924
  }
924
925
  }
925
926
 
926
927
  // parse the multiplexed stream,
927
928
  // and send messages to the appropriate requests
928
- var try_deleting = new Set()
929
929
  parse_multiplex_stream(r.body.getReader(), async (request, bytes) => {
930
930
  if (requests.has(request)) requests.get(request)(bytes)
931
931
  else try_deleting_request(request)
@@ -935,6 +935,12 @@ async function multiplex_fetch(url, params, mux_params) {
935
935
  // return a "fetch" for this multiplexer
936
936
  return async (url, params) => {
937
937
 
938
+ // if we already know the multiplexer is not working,
939
+ // then fallback to normal fetch
940
+ // (unless the user is specifically asking for multiplexing)
941
+ if ((await promise_done(mux_promise)) && (await mux_promise) === false && !params.headers.get('multiplex-through'))
942
+ return await normal_fetch(url, params)
943
+
938
944
  // make up a new request id (unless it is being overriden)
939
945
  var request = params.headers.get('multiplex-through')?.split('/')[4]
940
946
  ?? random_base64url(Math.ceil((mux_params?.id_bits ?? 72) / 6))
@@ -982,8 +988,6 @@ async function multiplex_fetch(url, params, mux_params) {
982
988
 
983
989
  // do the underlying fetch
984
990
  try {
985
- var mux_was_done = await promise_done(mux_promise)
986
-
987
991
  var res = await normal_fetch(url, params)
988
992
 
989
993
  if (res.status === 409) {
@@ -991,7 +995,7 @@ async function multiplex_fetch(url, params, mux_params) {
991
995
  if (e.error === 'Request already multiplexed') throw new Error(e.error)
992
996
  }
993
997
 
994
- if (res.status === 424 && !mux_was_done) {
998
+ if (res.status === 424) {
995
999
  // this error will trigger a retry if the user is using that option
996
1000
  throw new Error('multiplexer not yet connected')
997
1001
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "1.3.48",
3
+ "version": "1.3.49",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/server.js"