braid-http 1.3.99 → 1.3.102
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 +21 -0
- package/braid-http-server.js +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -385,6 +385,27 @@ var braidify = require('braid-http').http-server
|
|
|
385
385
|
nbraidify.enable_multiplex = true // or false
|
|
386
386
|
```
|
|
387
387
|
|
|
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
|
+
|
|
388
409
|
## Testing
|
|
389
410
|
|
|
390
411
|
Run all tests from the command line:
|
package/braid-http-server.js
CHANGED
|
@@ -395,6 +395,9 @@ function braidify (req, res, next) {
|
|
|
395
395
|
// find the multiplexer object (contains a response object)
|
|
396
396
|
var m = braidify.multiplexers?.get(multiplexer)
|
|
397
397
|
if (!m) {
|
|
398
|
+
// free cors to multiplexer errors
|
|
399
|
+
free_cors(res)
|
|
400
|
+
|
|
398
401
|
req.is_multiplexer = res.is_multiplexer = true
|
|
399
402
|
res.writeHead(424, 'Multiplexer no exist', {'Bad-Multiplexer': multiplexer})
|
|
400
403
|
return res.end(`multiplexer ${multiplexer} does not exist`)
|
|
@@ -402,6 +405,9 @@ function braidify (req, res, next) {
|
|
|
402
405
|
|
|
403
406
|
// if this request-id already exists, respond with an error
|
|
404
407
|
if (m.requests.has(request)) {
|
|
408
|
+
// free cors to multiplexer errors
|
|
409
|
+
free_cors(res)
|
|
410
|
+
|
|
405
411
|
req.is_multiplexer = res.is_multiplexer = true
|
|
406
412
|
res.writeHead(409, 'Conflict', {'Content-Type': 'application/json'})
|
|
407
413
|
return res.end(JSON.stringify({
|