braid-http 1.3.97 → 1.3.99
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 +3 -2
- package/braid-http-server.js +46 -0
- package/package.json +1 -1
package/braid-http-client.js
CHANGED
|
@@ -1086,7 +1086,8 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
|
|
|
1086
1086
|
var mux_created_promise = (async () => {
|
|
1087
1087
|
// attempt to establish a multiplexed connection
|
|
1088
1088
|
try {
|
|
1089
|
-
|
|
1089
|
+
// Disable MULTIPLEX method for now — go straight to POST
|
|
1090
|
+
if (true || mux_params?.via === 'POST'
|
|
1090
1091
|
|| multiplex_fetch.post_only?.has(origin)) throw 'skip multiplex method'
|
|
1091
1092
|
var r = await braid_fetch(`${origin}/${multiplexer}`, {
|
|
1092
1093
|
signal: mux_aborter.signal,
|
|
@@ -1137,7 +1138,7 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
|
|
|
1137
1138
|
// and send messages to the appropriate requests
|
|
1138
1139
|
parse_multiplex_stream(r.body.getReader(), async (request, bytes) => {
|
|
1139
1140
|
if (requests.has(request)) requests.get(request)(bytes)
|
|
1140
|
-
else try_deleting_request(request)
|
|
1141
|
+
else try_deleting_request(request).catch(e => {})
|
|
1141
1142
|
}, e => cleanup_multiplexer(e))
|
|
1142
1143
|
})()
|
|
1143
1144
|
|
package/braid-http-server.js
CHANGED
|
@@ -220,6 +220,43 @@ function parse_content_range (range_string) {
|
|
|
220
220
|
return [unit, range]
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
+
|
|
224
|
+
// Guard against double-braidification.
|
|
225
|
+
//
|
|
226
|
+
// Libraries (like braid-text &braid-blob) call braidify on the same
|
|
227
|
+
// request/response. We can't let it run twice on the same request. That can
|
|
228
|
+
// cause e.g. duplicate multiplexer request-id errors (409).
|
|
229
|
+
var braidify_version = require('./package.json').version
|
|
230
|
+
var warned_about_braidify_dupe = false
|
|
231
|
+
function warn_braidify_dupe (req) {
|
|
232
|
+
function version_bigger (a, b) {
|
|
233
|
+
var pa = a.split('.').map(Number)
|
|
234
|
+
var pb = b.split('.').map(Number)
|
|
235
|
+
for (var i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
236
|
+
if ((pa[i] || 0) > (pb[i] || 0)) return true
|
|
237
|
+
if ((pa[i] || 0) < (pb[i] || 0)) return false
|
|
238
|
+
}
|
|
239
|
+
return false
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (!warned_about_braidify_dupe) {
|
|
243
|
+
var installed = req._braidified
|
|
244
|
+
var major_mismatch = installed.split('.')[0] !== braidify_version.split('.')[0]
|
|
245
|
+
var dominated = version_bigger(braidify_version, installed)
|
|
246
|
+
|
|
247
|
+
if (major_mismatch || dominated)
|
|
248
|
+
console.warn('braid-http: braidify already applied (v' + installed
|
|
249
|
+
+ '), skipping v' + braidify_version
|
|
250
|
+
+ (major_mismatch
|
|
251
|
+
? ' — major version mismatch, things may break'
|
|
252
|
+
: ' — installed version is older, may lack features'))
|
|
253
|
+
|
|
254
|
+
warned_about_braidify_dupe = true
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
// The main server function!
|
|
223
260
|
function braidify (req, res, next) {
|
|
224
261
|
if (typeof req === 'function') {
|
|
225
262
|
var handler = req
|
|
@@ -227,6 +264,15 @@ function braidify (req, res, next) {
|
|
|
227
264
|
braidify(req, res, () => handler(req, res, next))
|
|
228
265
|
}
|
|
229
266
|
|
|
267
|
+
|
|
268
|
+
// Guard against double-braidification.
|
|
269
|
+
if (req._braidified) {
|
|
270
|
+
warn_braidify_dupe(req)
|
|
271
|
+
return next?.()
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
req._braidified = braidify_version
|
|
275
|
+
|
|
230
276
|
// console.log('\n## Braidifying', req.method, req.url, req.headers.peer)
|
|
231
277
|
|
|
232
278
|
// Prevent uncaught EPIPE crashes on client disconnect
|