braid-http 1.3.35 → 1.3.36
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 +7 -6
- package/package.json +1 -1
package/braid-http-client.js
CHANGED
|
@@ -308,12 +308,13 @@ async function braid_fetch (url, params = {}) {
|
|
|
308
308
|
|
|
309
309
|
// try multiplexing if either of these is true:
|
|
310
310
|
// - they explicitly want multiplexing
|
|
311
|
-
// -
|
|
312
|
-
|
|
311
|
+
// - we have already seen "after" subscriptions to the same origin
|
|
312
|
+
var mux_params = params.multiplexer ?? braid_fetch.multiplexer
|
|
313
|
+
if (mux_params &&
|
|
313
314
|
(params.headers.has('multiplexer') ||
|
|
314
315
|
(params.headers.has('subscribe') &&
|
|
315
|
-
braid_fetch.subscription_counts?.[origin] > 1))) {
|
|
316
|
-
res = await multiplex_fetch(url, params)
|
|
316
|
+
braid_fetch.subscription_counts?.[origin] > (mux_params.after ?? 1)))) {
|
|
317
|
+
res = await multiplex_fetch(url, params, mux_params)
|
|
317
318
|
} else {
|
|
318
319
|
res = await normal_fetch(url, params)
|
|
319
320
|
}
|
|
@@ -833,7 +834,7 @@ function parse_body (state) {
|
|
|
833
834
|
// doesn't exist already, then performs a fetch providing the multiplexer header.
|
|
834
835
|
// This tells the server to send the results to the given multiplexer.
|
|
835
836
|
//
|
|
836
|
-
async function multiplex_fetch(url, params) {
|
|
837
|
+
async function multiplex_fetch(url, params, mux_params) {
|
|
837
838
|
var origin = new URL(url, typeof document !== 'undefined' ? document.baseURI : undefined).origin
|
|
838
839
|
|
|
839
840
|
// the mux_key is the same as the origin, unless it is being overriden
|
|
@@ -852,7 +853,7 @@ async function multiplex_fetch(url, params) {
|
|
|
852
853
|
var mux_promise = (async () => {
|
|
853
854
|
// attempt to establish a multiplexed connection
|
|
854
855
|
try {
|
|
855
|
-
if (
|
|
856
|
+
if (mux_params?.via && mux_params.via !== 'method') throw 'skip to trying header'
|
|
856
857
|
var r = await braid_fetch(`${origin}/${multiplexer}`, {method: 'MULTIPLEX', headers: {'Multiplex-Version': '0.0.1'}, retry: true})
|
|
857
858
|
if (!r.ok || r.headers.get('Multiplex-Version') !== '0.0.1') throw 'bad'
|
|
858
859
|
} catch (e) {
|