braid-http 1.3.59 → 1.3.61
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 +15 -8
- package/braid-http-client.js +7 -4
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
# Braid-HTTP
|
|
2
2
|
|
|
3
|
-
This
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
This [ponyfill](https://ponyfill.com/) library extends the HTTP
|
|
4
|
+
implementations of Browsers and Nodejs with Braid-HTTP; transforming them from
|
|
5
|
+
*state transfer* to *state synchronization* systems.
|
|
6
|
+
|
|
7
|
+
These features are provided in an elegant, backwards-compatible way:
|
|
8
|
+
- Browsers: get a drop-in replacement for `fetch()`
|
|
9
|
+
- Nodejs: get a route handler that adds abilities to the `http`, `https`, and `http2` modules
|
|
10
|
+
|
|
11
|
+
It conforms to the [Braid-HTTP
|
|
12
|
+
v04](https://github.com/braid-org/braid-spec/blob/master/draft-toomim-httpbis-braid-http-04.txt)
|
|
13
|
+
specification, with the additional [HTTP
|
|
14
|
+
Multiresponse](https://braid.org/meeting-89) and [Multiplexing
|
|
15
|
+
v1.0](https://braid.org/protocol/multiplexing) extensions.
|
|
9
16
|
|
|
10
17
|
Developed in [braid.org](https://braid.org).
|
|
11
18
|
|
|
@@ -163,7 +170,7 @@ require('http').createServer(
|
|
|
163
170
|
version: ['greg'],
|
|
164
171
|
body: JSON.stringify({greg: 'greg'})
|
|
165
172
|
})
|
|
166
|
-
}
|
|
173
|
+
})
|
|
167
174
|
).listen(9935)
|
|
168
175
|
```
|
|
169
176
|
|
|
@@ -284,4 +291,4 @@ response connection dies, and thus you cannot attach a `.catch()` handler to
|
|
|
284
291
|
automatically reconnect. (See
|
|
285
292
|
[issue #980](https://github.com/node-fetch/node-fetch/issues/980) and
|
|
286
293
|
[#753](https://github.com/node-fetch/node-fetch/issues/753).) We recommend
|
|
287
|
-
using the `http`
|
|
294
|
+
using the `http` client on nodejs instead.
|
package/braid-http-client.js
CHANGED
|
@@ -949,7 +949,7 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
|
|
|
949
949
|
if (!try_deleting.has(request)) {
|
|
950
950
|
try_deleting.add(request)
|
|
951
951
|
try {
|
|
952
|
-
var mux_was_done = await promise_done(
|
|
952
|
+
var mux_was_done = await promise_done(mux_created_promise)
|
|
953
953
|
|
|
954
954
|
var r = await braid_fetch(`${origin}/.well-known/multiplexer/${multiplexer}/${request}`, {
|
|
955
955
|
method: 'DELETE',
|
|
@@ -979,7 +979,10 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
|
|
|
979
979
|
}
|
|
980
980
|
}
|
|
981
981
|
|
|
982
|
-
|
|
982
|
+
// This promise resolves when the create_multiplexer request responds.
|
|
983
|
+
// - its value is undefined if successfully created
|
|
984
|
+
// - its value is false if creation failed
|
|
985
|
+
var mux_created_promise = (async () => {
|
|
983
986
|
// attempt to establish a multiplexed connection
|
|
984
987
|
try {
|
|
985
988
|
if (mux_params?.via === 'POST') throw 'skip multiplex method'
|
|
@@ -1039,7 +1042,7 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
|
|
|
1039
1042
|
|
|
1040
1043
|
// if we already know the multiplexer is not working,
|
|
1041
1044
|
// then fallback to normal fetch
|
|
1042
|
-
if ((await promise_done(
|
|
1045
|
+
if ((await promise_done(mux_created_promise)) && (await mux_created_promise) === false) {
|
|
1043
1046
|
// if the user is specifically asking for multiplexing,
|
|
1044
1047
|
// throw an error instead
|
|
1045
1048
|
if (params.headers.get('multiplex-through')) throw new Error('multiplexer failed')
|
|
@@ -1105,7 +1108,7 @@ async function create_multiplexer(origin, mux_key, params, mux_params, attempt)
|
|
|
1105
1108
|
|
|
1106
1109
|
// do the underlying fetch
|
|
1107
1110
|
try {
|
|
1108
|
-
var mux_was_done = await promise_done(
|
|
1111
|
+
var mux_was_done = await promise_done(mux_created_promise)
|
|
1109
1112
|
|
|
1110
1113
|
// callback for testing
|
|
1111
1114
|
mux_params?.onFetch?.(url, params)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "braid-http",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.61",
|
|
4
4
|
"description": "An implementation of Braid-HTTP for Node.js and Browsers",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node test/server.js"
|
|
@@ -29,5 +29,8 @@
|
|
|
29
29
|
"node-fetch": "^2.6.1",
|
|
30
30
|
"parse-headers": "^2.0.3",
|
|
31
31
|
"web-streams-node": "^0.4.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"express": "^4.21.2"
|
|
32
35
|
}
|
|
33
36
|
}
|