braid-http 1.3.95 → 1.3.96

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.
@@ -1046,6 +1046,8 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
1046
1046
 
1047
1047
  async function try_deleting_request(request) {
1048
1048
  if (!try_deleting.has(request)) {
1049
+ // If the multiplexer is already known to be dead, skip the DELETE
1050
+ if (mux_error) return
1049
1051
  try_deleting.add(request)
1050
1052
  try {
1051
1053
  var mux_was_done = await promise_done(mux_created_promise)
@@ -1084,7 +1086,8 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
1084
1086
  var mux_created_promise = (async () => {
1085
1087
  // attempt to establish a multiplexed connection
1086
1088
  try {
1087
- if (mux_params?.via === 'POST') throw 'skip multiplex method'
1089
+ if (mux_params?.via === 'POST'
1090
+ || multiplex_fetch.post_only?.has(origin)) throw 'skip multiplex method'
1088
1091
  var r = await braid_fetch(`${origin}/${multiplexer}`, {
1089
1092
  signal: mux_aborter.signal,
1090
1093
  method: 'MULTIPLEX',
@@ -1101,7 +1104,9 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
1101
1104
  throw 'bad'
1102
1105
  } catch (e) {
1103
1106
  // some servers don't like custom methods,
1104
- // so let's try with a well-known url
1107
+ // so let's try with a well-known url;
1108
+ // remember this so we skip MULTIPLEX next time
1109
+ ;(multiplex_fetch.post_only ||= new Set()).add(origin)
1105
1110
  try {
1106
1111
  r = await braid_fetch(`${origin}/.well-known/multiplexer/${multiplexer}`,
1107
1112
  {method: 'POST',
@@ -1173,6 +1178,7 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
1173
1178
  var buffers = []
1174
1179
  var bytes_available = () => {}
1175
1180
  var request_error = null
1181
+ var established = false
1176
1182
 
1177
1183
  // this utility calls the callback whenever new data is available to process
1178
1184
  async function process_buffers(cb) {
@@ -1203,7 +1209,7 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
1203
1209
  if (!requests.size) not_used_timeout = setTimeout(() => mux_aborter.abort(), mux_params?.not_used_timeout ?? 1000 * 20)
1204
1210
  request_error = e
1205
1211
  bytes_available()
1206
- if (e !== 'retry') await try_deleting_request(request)
1212
+ if (e !== 'retry' && established) await try_deleting_request(request).catch(e => {})
1207
1213
  }
1208
1214
 
1209
1215
  // do the underlying fetch
@@ -1263,6 +1269,10 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
1263
1269
  + res.headers.get('Multiplex-Version'),
1264
1270
  { dont_retry: true })
1265
1271
 
1272
+ // The server acknowledged this request — mark it so we
1273
+ // know to send a DELETE if we need to tear it down later
1274
+ established = true
1275
+
1266
1276
  // we want to present the illusion that the connection is still open,
1267
1277
  // and therefor closable with "abort",
1268
1278
  // so we handle the abort ourselves to close the multiplexed request
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "1.3.95",
3
+ "version": "1.3.96",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/test.js",