braid-http 1.3.27 → 1.3.29
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 +6 -1
- package/braid-http-server.js +11 -9
- package/package.json +1 -1
package/braid-http-client.js
CHANGED
|
@@ -965,6 +965,11 @@ async function multiplex_fetch(url, params) {
|
|
|
965
965
|
throw new Error('multiplexer not yet connected')
|
|
966
966
|
}
|
|
967
967
|
|
|
968
|
+
// if the response says it's ok,
|
|
969
|
+
// but it's is not a multiplexed response,
|
|
970
|
+
// fall back to as if it was a normal fetch
|
|
971
|
+
if (res.ok && res.status !== 293) return res
|
|
972
|
+
|
|
968
973
|
if (res.status !== 293) throw new Error('Could not establish multiplexed stream ' + params.headers.get('multiplexer') + ', got status: ' + res.status)
|
|
969
974
|
|
|
970
975
|
if (res.headers.get('Multiplex-Version') !== '0.0.1') throw new Error('Could not establish multiplexed stream ' + params.headers.get('multiplexer') + ', got unknown version: ' + res.headers.get('Multiplex-Version'))
|
|
@@ -1036,7 +1041,7 @@ async function multiplex_fetch(url, params) {
|
|
|
1036
1041
|
return res
|
|
1037
1042
|
} catch (e) {
|
|
1038
1043
|
// if we had an error, be sure to unregister ourselves
|
|
1039
|
-
|
|
1044
|
+
unset(e)
|
|
1040
1045
|
throw e
|
|
1041
1046
|
}
|
|
1042
1047
|
}
|
package/braid-http-server.js
CHANGED
|
@@ -277,22 +277,24 @@ function braidify (req, res, next) {
|
|
|
277
277
|
return res.write(`\r\n`)
|
|
278
278
|
} else {
|
|
279
279
|
// in this case, we're closing the given stream
|
|
280
|
-
var m = braidify.multiplexers?.get(multiplexer)
|
|
281
280
|
|
|
282
281
|
// if the multiplexer doesn't exist, send an error
|
|
282
|
+
var m = braidify.multiplexers?.get(multiplexer)
|
|
283
283
|
if (!m) {
|
|
284
|
-
var msg = `multiplexer ${multiplexer} does not exist`
|
|
285
284
|
res.writeHead(400, {'Content-Type': 'text/plain'})
|
|
286
|
-
res.end(
|
|
287
|
-
return
|
|
285
|
+
return res.end(`multiplexer /${multiplexer} does not exist`)
|
|
288
286
|
}
|
|
289
287
|
|
|
290
|
-
//
|
|
288
|
+
// if the stream doesn't exist, send an error
|
|
291
289
|
let s = m.streams.get(stream)
|
|
292
|
-
if (s) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
290
|
+
if (!s) {
|
|
291
|
+
res.writeHead(400, {'Content-Type': 'text/plain'})
|
|
292
|
+
return res.end(`stream /${multiplexer}/${stream} does not exist`)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// remove this stream, and notify it
|
|
296
|
+
m.streams.delete(stream)
|
|
297
|
+
s()
|
|
296
298
|
|
|
297
299
|
// let the requester know we succeeded
|
|
298
300
|
res.writeHead(200, { 'Multiplex-Version': '0.0.1' })
|