braid-http 1.3.34 → 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 +9 -10
- 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
|
|
@@ -848,19 +849,17 @@ async function multiplex_fetch(url, params) {
|
|
|
848
849
|
|
|
849
850
|
var streams = new Map()
|
|
850
851
|
var mux_error = null
|
|
851
|
-
var using_multiplex_well_known_url = false
|
|
852
852
|
|
|
853
853
|
var mux_promise = (async () => {
|
|
854
854
|
// attempt to establish a multiplexed connection
|
|
855
855
|
try {
|
|
856
|
-
if (
|
|
856
|
+
if (mux_params?.via && mux_params.via !== 'method') throw 'skip to trying header'
|
|
857
857
|
var r = await braid_fetch(`${origin}/${multiplexer}`, {method: 'MULTIPLEX', headers: {'Multiplex-Version': '0.0.1'}, retry: true})
|
|
858
858
|
if (!r.ok || r.headers.get('Multiplex-Version') !== '0.0.1') throw 'bad'
|
|
859
859
|
} catch (e) {
|
|
860
860
|
// some servers don't like custom methods,
|
|
861
861
|
// so let's try with a custom header
|
|
862
862
|
try {
|
|
863
|
-
using_multiplex_well_known_url = true
|
|
864
863
|
r = await braid_fetch(`${origin}/.well-known/multiplex/${multiplexer}`, {headers: {'Multiplex-Version': '0.0.1'}, retry: true})
|
|
865
864
|
|
|
866
865
|
if (!r.ok) throw new Error('status not ok: ' + r.status)
|
|
@@ -937,8 +936,8 @@ async function multiplex_fetch(url, params) {
|
|
|
937
936
|
stream_error = e
|
|
938
937
|
bytes_available()
|
|
939
938
|
try {
|
|
940
|
-
var r = await braid_fetch(
|
|
941
|
-
|
|
939
|
+
var r = await braid_fetch(`${origin}/.well-known/multiplex${params.headers.get('multiplexer')}`, {
|
|
940
|
+
method: 'DELETE',
|
|
942
941
|
headers: { 'Multiplex-Version': '0.0.1' }, retry: true
|
|
943
942
|
})
|
|
944
943
|
|