braid-http 1.3.47 → 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.
- package/braid-http-client.js +14 -5
- package/package.json +1 -1
package/braid-http-client.js
CHANGED
|
@@ -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
|
-
|
|
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,11 +988,14 @@ 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
|
-
if (res.status ===
|
|
993
|
+
if (res.status === 409) {
|
|
994
|
+
var e = await r.json()
|
|
995
|
+
if (e.error === 'Request already multiplexed') throw new Error(e.error)
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
if (res.status === 424) {
|
|
990
999
|
// this error will trigger a retry if the user is using that option
|
|
991
1000
|
throw new Error('multiplexer not yet connected')
|
|
992
1001
|
}
|