braid-http 1.3.61 → 1.3.62
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/README.md +1 -8
- package/braid-http-client.js +7 -3
- package/braid-http-server.js +6 -3
- package/package.json +2 -10
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ npm install braid-http
|
|
|
37
37
|
|
|
38
38
|
```javascript
|
|
39
39
|
// Import with require()
|
|
40
|
-
require('braid-http').fetch // A polyfill for
|
|
40
|
+
require('braid-http').fetch // A polyfill for fetch
|
|
41
41
|
require('braid-http').http_client // A polyfill for require('http') clients
|
|
42
42
|
require('braid-http').http_server // A polyfill for require('http') servers
|
|
43
43
|
|
|
@@ -285,10 +285,3 @@ fetch('https://localhost:3009/chat',
|
|
|
285
285
|
x => console.log('Got ', x)
|
|
286
286
|
)
|
|
287
287
|
```
|
|
288
|
-
|
|
289
|
-
Note: the current version of `node-fetch` doesn't properly throw errors when a
|
|
290
|
-
response connection dies, and thus you cannot attach a `.catch()` handler to
|
|
291
|
-
automatically reconnect. (See
|
|
292
|
-
[issue #980](https://github.com/node-fetch/node-fetch/issues/980) and
|
|
293
|
-
[#753](https://github.com/node-fetch/node-fetch/issues/753).) We recommend
|
|
294
|
-
using the `http` client on nodejs instead.
|
package/braid-http-client.js
CHANGED
|
@@ -122,7 +122,7 @@ var normal_fetch,
|
|
|
122
122
|
|
|
123
123
|
if (is_nodejs) {
|
|
124
124
|
// Nodejs
|
|
125
|
-
normal_fetch = fetch
|
|
125
|
+
normal_fetch = typeof fetch !== 'undefined' && fetch
|
|
126
126
|
} else {
|
|
127
127
|
// Web Browser
|
|
128
128
|
normal_fetch = window.fetch
|
|
@@ -860,7 +860,7 @@ function get_binary_length(x) {
|
|
|
860
860
|
function deep_copy(x) {
|
|
861
861
|
if (x === null || typeof x !== 'object') return x
|
|
862
862
|
if (Array.isArray(x)) return x.map(x => deep_copy(x))
|
|
863
|
-
if (
|
|
863
|
+
if (x.constructor === Object)
|
|
864
864
|
return Object.fromEntries(Object.entries(x).map(([k, x]) => [k, deep_copy(x)]))
|
|
865
865
|
return x
|
|
866
866
|
}
|
|
@@ -882,7 +882,11 @@ async function promise_done(promise) {
|
|
|
882
882
|
}
|
|
883
883
|
|
|
884
884
|
function random_base64url(n) {
|
|
885
|
-
|
|
885
|
+
var buf = new Uint8Array(n)
|
|
886
|
+
var crypt = (typeof crypto !== 'undefined') ? crypto : require('crypto')
|
|
887
|
+
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
|
|
888
|
+
return [...(crypt.webcrypto ?? crypt).getRandomValues(buf)].
|
|
889
|
+
map(x => chars[x % 64]).join('')
|
|
886
890
|
}
|
|
887
891
|
|
|
888
892
|
|
package/braid-http-server.js
CHANGED
|
@@ -348,12 +348,14 @@ function braidify (req, res, next) {
|
|
|
348
348
|
// find the multiplexer object (contains a response object)
|
|
349
349
|
var m = braidify.multiplexers?.get(multiplexer)
|
|
350
350
|
if (!m) {
|
|
351
|
+
req.is_multiplexer = res.is_multiplexer = true
|
|
351
352
|
res.writeHead(424, 'Multiplexer no exist', {'Bad-Multiplexer': multiplexer})
|
|
352
353
|
return res.end(`multiplexer ${multiplexer} does not exist`)
|
|
353
354
|
}
|
|
354
355
|
|
|
355
356
|
// if this request-id already exists, respond with an error
|
|
356
357
|
if (m.requests.has(request)) {
|
|
358
|
+
req.is_multiplexer = res.is_multiplexer = true
|
|
357
359
|
res.writeHead(409, 'Conflict', {'Content-Type': 'application/json'})
|
|
358
360
|
return res.end(JSON.stringify({
|
|
359
361
|
error: 'Request already multiplexed',
|
|
@@ -621,7 +623,7 @@ async function send_update(res, data, url, peer) {
|
|
|
621
623
|
// Validate body format
|
|
622
624
|
if (body !== undefined) {
|
|
623
625
|
assert(typeof body === 'string' || get_binary_length(body) != null)
|
|
624
|
-
if (body instanceof Blob) body = await body.arrayBuffer()
|
|
626
|
+
if (typeof Blob !== 'undefined' && body instanceof Blob) body = await body.arrayBuffer()
|
|
625
627
|
}
|
|
626
628
|
|
|
627
629
|
// Validate patches format
|
|
@@ -638,7 +640,8 @@ async function send_update(res, data, url, peer) {
|
|
|
638
640
|
assert('content' in p)
|
|
639
641
|
assert(typeof p.content === 'string'
|
|
640
642
|
|| get_binary_length(p.content) != null)
|
|
641
|
-
if (
|
|
643
|
+
if (typeof Blob !== 'undefined' && p.content instanceof Blob)
|
|
644
|
+
p.content = await p.content.arrayBuffer()
|
|
642
645
|
}
|
|
643
646
|
}
|
|
644
647
|
|
|
@@ -708,7 +711,7 @@ async function send_update(res, data, url, peer) {
|
|
|
708
711
|
function get_binary_length(x) {
|
|
709
712
|
return x instanceof ArrayBuffer ? x.byteLength :
|
|
710
713
|
x instanceof Uint8Array ? x.length :
|
|
711
|
-
x instanceof Blob ? x.size :
|
|
714
|
+
typeof Blob !== 'undefined' && x instanceof Blob ? x.size :
|
|
712
715
|
x instanceof Buffer ? x.length : undefined
|
|
713
716
|
}
|
|
714
717
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "braid-http",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.62",
|
|
4
4
|
"description": "An implementation of Braid-HTTP for Node.js and Browsers",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node test/server.js"
|
|
@@ -19,16 +19,8 @@
|
|
|
19
19
|
"require": "./index.js",
|
|
20
20
|
"import": "./index.mjs"
|
|
21
21
|
},
|
|
22
|
-
"browser": {
|
|
23
|
-
"node-web-streams": false,
|
|
24
|
-
"node-fetch": false,
|
|
25
|
-
"abort-controller": false
|
|
26
|
-
},
|
|
27
22
|
"dependencies": {
|
|
28
|
-
"
|
|
29
|
-
"node-fetch": "^2.6.1",
|
|
30
|
-
"parse-headers": "^2.0.3",
|
|
31
|
-
"web-streams-node": "^0.4.0"
|
|
23
|
+
"parse-headers": "^2.0.3"
|
|
32
24
|
},
|
|
33
25
|
"devDependencies": {
|
|
34
26
|
"express": "^4.21.2"
|