braid-http 1.3.28 → 1.3.30
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 +10 -13
- package/braid-http-server.js +11 -9
- package/package.json +1 -1
package/braid-http-client.js
CHANGED
|
@@ -265,6 +265,7 @@ async function braid_fetch (url, params = {}) {
|
|
|
265
265
|
var retry = params.retry && // only try to reconnect if the user has chosen to
|
|
266
266
|
e.name !== "AbortError" && // don't retry if the user has chosen to abort
|
|
267
267
|
!e.startsWith?.('Parse error in headers') && // in this case, the server is spewing garbage, so reconnecting might be bad
|
|
268
|
+
!e.message?.startsWith?.('Could not establish multiplexed stream') && // the server has told us no, or is using a different version of multiplexing
|
|
268
269
|
!cb_running // if an error is thrown in the callback, then it may not be good to reconnect, and generate more errors
|
|
269
270
|
|
|
270
271
|
if (retry && !original_signal?.aborted) {
|
|
@@ -885,14 +886,12 @@ async function multiplex_fetch(url, params) {
|
|
|
885
886
|
|
|
886
887
|
// return a "fetch" for this multiplexer
|
|
887
888
|
return async (url, params) => {
|
|
888
|
-
|
|
889
|
-
if
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
}
|
|
895
|
-
}
|
|
889
|
+
|
|
890
|
+
// if we already know the multiplexer is not working,
|
|
891
|
+
// then fallback to normal fetch
|
|
892
|
+
// (unless the user is specifically asking for multiplexing)
|
|
893
|
+
if ((await promise_done(mux_promise)) && (await mux_promise) === false && !params.headers.get('multiplexer'))
|
|
894
|
+
return await normal_fetch(url, params)
|
|
896
895
|
|
|
897
896
|
// make up a new stream id (unless it is being overriden)
|
|
898
897
|
var stream = params.headers.get('multiplexer')?.split('/')[2] ?? Math.random().toString(36).slice(2)
|
|
@@ -958,10 +957,8 @@ async function multiplex_fetch(url, params) {
|
|
|
958
957
|
try {
|
|
959
958
|
var res = await normal_fetch(url, params)
|
|
960
959
|
|
|
961
|
-
if (
|
|
962
|
-
|
|
963
|
-
!(await promise_done(mux_promise))) {
|
|
964
|
-
// this error will trigger a retry if the user is using that
|
|
960
|
+
if (res.status === 422 && !(await promise_done(mux_promise))) {
|
|
961
|
+
// this error will trigger a retry if the user is using that option
|
|
965
962
|
throw new Error('multiplexer not yet connected')
|
|
966
963
|
}
|
|
967
964
|
|
|
@@ -1041,7 +1038,7 @@ async function multiplex_fetch(url, params) {
|
|
|
1041
1038
|
return res
|
|
1042
1039
|
} catch (e) {
|
|
1043
1040
|
// if we had an error, be sure to unregister ourselves
|
|
1044
|
-
|
|
1041
|
+
unset(e)
|
|
1045
1042
|
throw e
|
|
1046
1043
|
}
|
|
1047
1044
|
}
|
package/braid-http-server.js
CHANGED
|
@@ -277,22 +277,24 @@ function braidify (req, res, next) {
|
|
|
277
277
|
return res.write(`\r\n`)
|
|
278
278
|
} else {
|
|
279
279
|
// in this case, we're closing the given stream
|
|
280
|
-
var m = braidify.multiplexers?.get(multiplexer)
|
|
281
280
|
|
|
282
281
|
// if the multiplexer doesn't exist, send an error
|
|
282
|
+
var m = braidify.multiplexers?.get(multiplexer)
|
|
283
283
|
if (!m) {
|
|
284
|
-
var msg = `multiplexer ${multiplexer} does not exist`
|
|
285
284
|
res.writeHead(400, {'Content-Type': 'text/plain'})
|
|
286
|
-
res.end(
|
|
287
|
-
return
|
|
285
|
+
return res.end(`multiplexer /${multiplexer} does not exist`)
|
|
288
286
|
}
|
|
289
287
|
|
|
290
|
-
//
|
|
288
|
+
// if the stream doesn't exist, send an error
|
|
291
289
|
let s = m.streams.get(stream)
|
|
292
|
-
if (s) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
290
|
+
if (!s) {
|
|
291
|
+
res.writeHead(400, {'Content-Type': 'text/plain'})
|
|
292
|
+
return res.end(`stream /${multiplexer}/${stream} does not exist`)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// remove this stream, and notify it
|
|
296
|
+
m.streams.delete(stream)
|
|
297
|
+
s()
|
|
296
298
|
|
|
297
299
|
// let the requester know we succeeded
|
|
298
300
|
res.writeHead(200, { 'Multiplex-Version': '0.0.1' })
|