braid-http 1.3.94 → 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.
package/README.md CHANGED
@@ -385,45 +385,23 @@ var braidify = require('braid-http').http-server
385
385
  nbraidify.enable_multiplex = true // or false
386
386
  ```
387
387
 
388
- ## Test Procedure
388
+ ## Testing
389
389
 
390
- Run tests from the command line:
390
+ Run all tests from the command line:
391
391
 
392
392
  ```
393
- node test/test.js
393
+ npm test
394
394
  ```
395
395
 
396
- Or run tests in a browser by starting the test server:
396
+ Run tests in a browser (auto-opens):
397
397
 
398
398
  ```
399
- node test/test.js --browser
399
+ npm run test:browser
400
400
  ```
401
401
 
402
- Then open https://localhost:9000 and make sure all the boxes turn green.
403
-
404
402
  You can also filter tests by name:
405
403
 
406
404
  ```
407
405
  node test/test.js --filter="version"
408
406
  ```
409
407
 
410
- For the complete browser test (including demos), use 3 terminals. In the first terminal start the demo chat server:
411
-
412
- ```
413
- cd demos/chat
414
- node server.js
415
- ```
416
-
417
- In the second terminal start the demo blog server:
418
- ```
419
- cd demos/blog
420
- node server.js
421
- ```
422
-
423
- And in the third terminal, start the test server:
424
- ```
425
- node test/test.js --browser
426
- ```
427
-
428
- Now open https://localhost:9000, make sure all the boxes turn green, and try out the demo chat and blog, sending a message in each.
429
-
@@ -483,7 +483,7 @@ async function braid_fetch (url, params = {}) {
483
483
 
484
484
  if (subscription_cb && res.ok) start_subscription(subscription_cb, subscription_error)
485
485
 
486
- if (subscription_cb && res.ok && params.onSubscriptionStatus) {
486
+ if (params.subscribe && params.onSubscriptionStatus && res.ok) {
487
487
  subscription_online = true
488
488
  params.onSubscriptionStatus({online: true})
489
489
  }
@@ -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,9 +1,10 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "1.3.94",
3
+ "version": "1.3.96",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
- "test": "node test/server.js"
6
+ "test": "node test/test.js",
7
+ "test:browser": "node test/test.js --browser"
7
8
  },
8
9
  "author": "Braid Working Group",
9
10
  "repository": "braid-org/braid-http",