braid-http 1.3.56 → 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.
- package/braid-http-client.js +4 -2
- package/braid-http-server.js +24 -7
- package/package.json +1 -1
package/braid-http-client.js
CHANGED
|
@@ -985,7 +985,8 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
|
|
|
985
985
|
signal: mux_aborter.signal,
|
|
986
986
|
method: 'MULTIPLEX',
|
|
987
987
|
headers: {'Multiplex-Version': multiplex_version},
|
|
988
|
-
retry: true
|
|
988
|
+
retry: true,
|
|
989
|
+
multiplex: false
|
|
989
990
|
})
|
|
990
991
|
if (r.status === 409) {
|
|
991
992
|
var e = await r.json()
|
|
@@ -1002,7 +1003,8 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
|
|
|
1002
1003
|
{method: 'POST',
|
|
1003
1004
|
signal: mux_aborter.signal,
|
|
1004
1005
|
headers: {'Multiplex-Version': multiplex_version},
|
|
1005
|
-
retry: true
|
|
1006
|
+
retry: true,
|
|
1007
|
+
multiplex: false})
|
|
1006
1008
|
if (r.status === 409) {
|
|
1007
1009
|
var e = await r.json()
|
|
1008
1010
|
if (e.error === 'Multiplexer already exists')
|
package/braid-http-server.js
CHANGED
|
@@ -221,6 +221,12 @@ function parse_content_range (range_string) {
|
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
function braidify (req, res, next) {
|
|
224
|
+
if (typeof req === 'function') {
|
|
225
|
+
var handler = req
|
|
226
|
+
return (req, res, next) =>
|
|
227
|
+
braidify(req, res, () => handler(req, res, next))
|
|
228
|
+
}
|
|
229
|
+
|
|
224
230
|
// console.log('\n## Braidifying', req.method, req.url, req.headers.peer)
|
|
225
231
|
|
|
226
232
|
// First, declare that we support Patches and JSON ranges.
|
|
@@ -245,16 +251,23 @@ function braidify (req, res, next) {
|
|
|
245
251
|
// Multiplexer stuff
|
|
246
252
|
var multiplex_version = '1.0'
|
|
247
253
|
if ((braidify.enable_multiplex ?? true) &&
|
|
248
|
-
(req.method === 'MULTIPLEX' || req.url.startsWith('/.well-known/multiplexer/'))
|
|
249
|
-
req.headers['multiplex-version'] === multiplex_version) {
|
|
250
|
-
|
|
251
|
-
// let the caller know we're handling things
|
|
252
|
-
req.is_multiplexer = res.is_multiplexer = true
|
|
254
|
+
(req.method === 'MULTIPLEX' || req.url.startsWith('/.well-known/multiplexer/'))) {
|
|
253
255
|
|
|
254
256
|
// free the cors
|
|
255
257
|
res.setHeader("Access-Control-Allow-Origin", "*")
|
|
256
258
|
res.setHeader("Access-Control-Allow-Methods", "*")
|
|
257
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
|
|
258
271
|
|
|
259
272
|
// parse the multiplexer id and request id from the url
|
|
260
273
|
var [multiplexer, request] = req.url.split('/').slice(req.method === 'MULTIPLEX' ? 1 : 3)
|
|
@@ -287,7 +300,7 @@ function braidify (req, res, next) {
|
|
|
287
300
|
res.writeHead(200, 'OK', {
|
|
288
301
|
'Multiplex-Version': multiplex_version,
|
|
289
302
|
'Incremental': '?1',
|
|
290
|
-
'Cache-Control': 'no-
|
|
303
|
+
'Cache-Control': 'no-store',
|
|
291
304
|
'X-Accel-Buffering': 'no',
|
|
292
305
|
...req.httpVersion !== '2.0' && {'Connection': 'keep-alive'}
|
|
293
306
|
})
|
|
@@ -367,7 +380,7 @@ function braidify (req, res, next) {
|
|
|
367
380
|
|
|
368
381
|
// copy any CORS headers from the user
|
|
369
382
|
var cors_headers = Object.entries(res2.getHeaders()).
|
|
370
|
-
filter(x => braidify.cors_headers.has(x
|
|
383
|
+
filter(x => braidify.cors_headers.has(x[0]))
|
|
371
384
|
|
|
372
385
|
if (og_stream) {
|
|
373
386
|
og_stream.respond({
|
|
@@ -434,6 +447,10 @@ function braidify (req, res, next) {
|
|
|
434
447
|
// we want to send a special message to the multiplexer saying so
|
|
435
448
|
res2.on('finish', () => m.res.write(`close response ${request}\r\n`))
|
|
436
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
|
+
|
|
437
454
|
// we want access to "res" to be forwarded to our fake "res2",
|
|
438
455
|
// so that it goes into the multiplexer
|
|
439
456
|
function* get_props(obj) {
|