braid-http 1.3.102 → 1.3.104

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
@@ -376,6 +376,14 @@ braid_fetch('/example', {multiplex: false, subscription: true})
376
376
  braid_fetch('/example', {multiplex: {after: 1}, subscription: true})
377
377
  ```
378
378
 
379
+ Note that this library implements [optimistic multiplexing](https://braid.org/protocol/multiplexing#optimistic-creation), which is faster, but can print this harmless error message to your JS console:
380
+
381
+ ```
382
+ GET /foo 424 (Multiplexer no exist; consider trying again)
383
+ ```
384
+
385
+ You can ignore this message.
386
+
379
387
  ### Server
380
388
 
381
389
  Configure mutliplexing with:
@@ -385,27 +393,6 @@ var braidify = require('braid-http').http-server
385
393
  nbraidify.enable_multiplex = true // or false
386
394
  ```
387
395
 
388
- ### How CORS works with Multiplexing
389
-
390
- When multiplexing is enabled, the library presents the illusion that
391
- everything is normal HTTP. Behind the scenes, a request/response pair is
392
- made to `.well-known/multiplexer/<id>` to establish the multiplexer
393
- channel — CORS is opened on this request. However, this request is hidden
394
- from client code (it happens inside `braid_fetch`) and the response is
395
- hidden from server code (it happens inside `braidify`).
396
-
397
- One might worry that a cross-origin GET without proper CORS could trick the
398
- server into piping its response through the multiplexer channel — and since
399
- CORS is opened on the multiplexer channel, the client could read data it
400
- shouldn't have access to. This doesn't happen, because the browser sends a
401
- preflight OPTIONS request before the actual GET. If the server doesn't
402
- return the proper CORS headers for that OPTIONS request, the browser never
403
- sends the GET, and no data flows through the multiplexer channel.
404
-
405
- Multiplexer error responses (e.g. 424 "Multiplexer no exist" or 409
406
- "Request already multiplexed") also include CORS headers, so that browsers
407
- can read the error details from cross-origin requests.
408
-
409
396
  ## Testing
410
397
 
411
398
  Run all tests from the command line:
@@ -289,8 +289,15 @@ function braidify (req, res, next) {
289
289
 
290
290
  // Parse the subscribe header
291
291
  var subscribe = req.headers.subscribe
292
- if (subscribe === '' || subscribe === 'true')
293
- subscribe = true
292
+ // If the subscribe header exists...
293
+ if ((subscribe === '' || subscribe)
294
+ // And this is a GET, because `Subscribe:` is only
295
+ // specified for GET thus far...
296
+ && req.method === 'GET')
297
+ // Then let's set 'subscribe' on. We default to "true", but if the
298
+ // client actually specified a value other than empty string '', let's
299
+ // use that rich value.
300
+ subscribe = subscribe || true
294
301
 
295
302
  // Define convenience variables
296
303
  req.version = version
@@ -399,7 +406,7 @@ function braidify (req, res, next) {
399
406
  free_cors(res)
400
407
 
401
408
  req.is_multiplexer = res.is_multiplexer = true
402
- res.writeHead(424, 'Multiplexer no exist', {'Bad-Multiplexer': multiplexer})
409
+ res.writeHead(424, 'Multiplexer no exist; cosnsider trying again', {'Bad-Multiplexer': multiplexer})
403
410
  return res.end(`multiplexer ${multiplexer} does not exist`)
404
411
  }
405
412
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "1.3.102",
3
+ "version": "1.3.104",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/test.js",