braid-http 1.3.57 → 1.3.58

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.
@@ -251,16 +251,23 @@ function braidify (req, res, next) {
251
251
  // Multiplexer stuff
252
252
  var multiplex_version = '1.0'
253
253
  if ((braidify.enable_multiplex ?? true) &&
254
- (req.method === 'MULTIPLEX' || req.url.startsWith('/.well-known/multiplexer/')) &&
255
- req.headers['multiplex-version'] === multiplex_version) {
256
-
257
- // let the caller know we're handling things
258
- req.is_multiplexer = res.is_multiplexer = true
254
+ (req.method === 'MULTIPLEX' || req.url.startsWith('/.well-known/multiplexer/'))) {
259
255
 
260
256
  // free the cors
261
257
  res.setHeader("Access-Control-Allow-Origin", "*")
262
258
  res.setHeader("Access-Control-Allow-Methods", "*")
263
259
  res.setHeader("Access-Control-Allow-Headers", "*")
260
+ res.setHeader("Access-Control-Expose-Headers", "*")
261
+ if (req.method === 'OPTIONS') return res.end()
262
+
263
+ // check the multiplexing protocol version
264
+ if (req.headers['multiplex-version'] !== multiplex_version) {
265
+ res.writeHead(400, 'Bad Multiplexer Version')
266
+ return res.end()
267
+ }
268
+
269
+ // let the caller know we're handling things
270
+ req.is_multiplexer = res.is_multiplexer = true
264
271
 
265
272
  // parse the multiplexer id and request id from the url
266
273
  var [multiplexer, request] = req.url.split('/').slice(req.method === 'MULTIPLEX' ? 1 : 3)
@@ -293,7 +300,7 @@ function braidify (req, res, next) {
293
300
  res.writeHead(200, 'OK', {
294
301
  'Multiplex-Version': multiplex_version,
295
302
  'Incremental': '?1',
296
- 'Cache-Control': 'no-cache',
303
+ 'Cache-Control': 'no-store',
297
304
  'X-Accel-Buffering': 'no',
298
305
  ...req.httpVersion !== '2.0' && {'Connection': 'keep-alive'}
299
306
  })
@@ -373,7 +380,7 @@ function braidify (req, res, next) {
373
380
 
374
381
  // copy any CORS headers from the user
375
382
  var cors_headers = Object.entries(res2.getHeaders()).
376
- filter(x => braidify.cors_headers.has(x.key))
383
+ filter(x => braidify.cors_headers.has(x[0]))
377
384
 
378
385
  if (og_stream) {
379
386
  og_stream.respond({
@@ -440,6 +447,10 @@ function braidify (req, res, next) {
440
447
  // we want to send a special message to the multiplexer saying so
441
448
  res2.on('finish', () => m.res.write(`close response ${request}\r\n`))
442
449
 
450
+ // copy over any headers which have already been set on res to res2
451
+ for (let x of Object.entries(res.getHeaders()))
452
+ res2.setHeader(...x)
453
+
443
454
  // we want access to "res" to be forwarded to our fake "res2",
444
455
  // so that it goes into the multiplexer
445
456
  function* get_props(obj) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "1.3.57",
3
+ "version": "1.3.58",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/server.js"