braid-http 1.3.58 → 1.3.60
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 +21 -10
- package/braid-http-client.js +4 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# Braid-HTTP
|
|
2
2
|
|
|
3
|
-
This
|
|
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.
|
|
4
16
|
|
|
5
17
|
Developed in [braid.org](https://braid.org).
|
|
6
18
|
|
|
@@ -143,30 +155,29 @@ var braidify = require('braid-http').http_server
|
|
|
143
155
|
import {http_server as braidify} from 'braid-http'
|
|
144
156
|
|
|
145
157
|
require('http').createServer(
|
|
146
|
-
(req, res) => {
|
|
147
|
-
//
|
|
148
|
-
braidify(req, res)
|
|
158
|
+
braidify((req, res) => {
|
|
159
|
+
// Now braid stuff is available on req and res
|
|
149
160
|
|
|
150
|
-
//
|
|
161
|
+
// So you can easily handle subscriptions
|
|
151
162
|
if (req.subscribe)
|
|
152
163
|
res.startSubscription({ onClose: _=> null })
|
|
153
164
|
// startSubscription automatically sets statusCode = 209
|
|
154
165
|
else
|
|
155
166
|
res.statusCode = 200
|
|
156
167
|
|
|
157
|
-
//
|
|
168
|
+
// And send updates over a subscription
|
|
158
169
|
res.sendUpdate({
|
|
159
170
|
version: ['greg'],
|
|
160
171
|
body: JSON.stringify({greg: 'greg'})
|
|
161
172
|
})
|
|
162
|
-
}
|
|
173
|
+
})
|
|
163
174
|
).listen(9935)
|
|
164
175
|
```
|
|
165
176
|
|
|
166
177
|
### Example Nodejs server with `require('express')`
|
|
167
178
|
|
|
168
|
-
|
|
169
|
-
added to every request and response.
|
|
179
|
+
Or if you're using `express`, you can just call `app.use(braidify)` to get
|
|
180
|
+
braid features added to every request and response.
|
|
170
181
|
|
|
171
182
|
```javascript
|
|
172
183
|
var braidify = require('braid-http').http_server
|
|
@@ -280,4 +291,4 @@ response connection dies, and thus you cannot attach a `.catch()` handler to
|
|
|
280
291
|
automatically reconnect. (See
|
|
281
292
|
[issue #980](https://github.com/node-fetch/node-fetch/issues/980) and
|
|
282
293
|
[#753](https://github.com/node-fetch/node-fetch/issues/753).) We recommend
|
|
283
|
-
using the `http`
|
|
294
|
+
using the `http` client on nodejs instead.
|
package/braid-http-client.js
CHANGED
|
@@ -900,14 +900,16 @@ async function multiplex_fetch(url, params, mux_params) {
|
|
|
900
900
|
var mux_key = params.headers.get('multiplex-through')?.split('/')[3] ?? origin
|
|
901
901
|
|
|
902
902
|
// create a new multiplexer if it doesn't exist for this origin
|
|
903
|
-
if (!multiplex_fetch.multiplexers)
|
|
903
|
+
if (!multiplex_fetch.multiplexers)
|
|
904
|
+
multiplex_fetch.multiplexers = {}
|
|
904
905
|
|
|
905
906
|
// this for-loop allows us to retry right away,
|
|
906
907
|
// in case of duplicate ids
|
|
907
908
|
for (let attempt = 1; ; attempt++) {
|
|
908
909
|
await new Promise(done => setTimeout(done, attempt >= 3 ? 1000 : 0))
|
|
909
910
|
|
|
910
|
-
if
|
|
911
|
+
// Create a multiplexer if it does not exist yet
|
|
912
|
+
multiplex_fetch.multiplexers[mux_key] ||=
|
|
911
913
|
create_multiplexer(origin, mux_key, params, mux_params, attempt)
|
|
912
914
|
|
|
913
915
|
// call the special fetch function for the multiplexer
|