braid-http 1.3.41 → 1.3.42
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 +19 -7
- package/braid-http-server.js +2 -0
- package/package.json +1 -1
package/braid-http-client.js
CHANGED
|
@@ -868,8 +868,19 @@ async function multiplex_fetch(url, params, skip_multiplex_method) {
|
|
|
868
868
|
|
|
869
869
|
// parse the multiplexed stream,
|
|
870
870
|
// and send messages to the appropriate requests
|
|
871
|
-
|
|
872
|
-
|
|
871
|
+
var try_deleting = new Set()
|
|
872
|
+
parse_multiplex_stream(r.body.getReader(), async (request, bytes) => {
|
|
873
|
+
if (requests.has(request)) {
|
|
874
|
+
requests.get(request)(bytes)
|
|
875
|
+
} else if (!try_deleting.has(request)) {
|
|
876
|
+
try_deleting.add(request)
|
|
877
|
+
try {
|
|
878
|
+
await braid_fetch(`${origin}/.well-known/multiplex/${multiplexer}/${request}`, {
|
|
879
|
+
method: 'DELETE',
|
|
880
|
+
headers: { 'Multiplex-Version': multiplex_version }, retry: true
|
|
881
|
+
})
|
|
882
|
+
} finally { try_deleting.delete(request) }
|
|
883
|
+
}
|
|
873
884
|
}, e => {
|
|
874
885
|
// the multiplexer stream has died.. let everyone know..
|
|
875
886
|
mux_error = e
|
|
@@ -1074,16 +1085,18 @@ async function parse_multiplex_stream(reader, cb, on_error) {
|
|
|
1074
1085
|
}
|
|
1075
1086
|
if (headerComplete) {
|
|
1076
1087
|
var headerStr = new TextDecoder().decode(buffers[0].slice(0, header_length))
|
|
1077
|
-
var m = headerStr.match(/^[\r\n]*((\d+) bytes for|close) request ([A-Za-z0-9_-]+)\r\n$/)
|
|
1088
|
+
var m = headerStr.match(/^[\r\n]*((\d+) bytes for|close|start) request ([A-Za-z0-9_-]+)\r\n$/)
|
|
1089
|
+
|
|
1078
1090
|
if (!m) throw new Error('invalid multiplex header')
|
|
1079
1091
|
request_id = m[3]
|
|
1080
1092
|
|
|
1081
1093
|
buffers[0] = buffers[0].slice(header_length)
|
|
1082
1094
|
buffers_size -= header_length
|
|
1083
1095
|
|
|
1084
|
-
if (m[1] === 'close') {
|
|
1085
|
-
cb(request_id)
|
|
1086
|
-
|
|
1096
|
+
if (m[1] === 'close' || m[1] === 'start') {
|
|
1097
|
+
cb(request_id, m[1] === 'start' ? new Uint8Array() : undefined)
|
|
1098
|
+
header_length = 0
|
|
1099
|
+
header_started = false
|
|
1087
1100
|
} else chunk_size = 1 * m[2]
|
|
1088
1101
|
} else break
|
|
1089
1102
|
} else if (chunk_size !== null && buffers_size >= chunk_size) {
|
|
@@ -1098,7 +1111,6 @@ async function parse_multiplex_stream(reader, cb, on_error) {
|
|
|
1098
1111
|
cb(request_id, chunk)
|
|
1099
1112
|
|
|
1100
1113
|
chunk_size = null
|
|
1101
|
-
request_id = null
|
|
1102
1114
|
header_length = 0
|
|
1103
1115
|
header_started = false
|
|
1104
1116
|
} else break
|
package/braid-http-server.js
CHANGED
|
@@ -340,6 +340,8 @@ function braidify (req, res, next) {
|
|
|
340
340
|
return res.end(`multiplexer ${multiplexer} does not exist`)
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
+
m.res.write(`start request ${request}\r\n`)
|
|
344
|
+
|
|
343
345
|
// let the requester know we've multiplexed their response
|
|
344
346
|
var og_stream = res.stream
|
|
345
347
|
var og_socket = res.socket
|