braid-http 1.3.58 → 1.3.59
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 +12 -8
- package/braid-http-client.js +4 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Braid-HTTP
|
|
2
2
|
|
|
3
|
-
This polyfill library implements the [Braid-HTTP v04
|
|
3
|
+
This polyfill library implements the [Braid-HTTP v04
|
|
4
|
+
protocol](https://github.com/braid-org/braid-spec/blob/master/draft-toomim-httpbis-braid-http-04.txt),
|
|
5
|
+
with [HTTP Multiresponse](https://braid.org/meeting-89), and [Multiplexing
|
|
6
|
+
v1.0](https://braid.org/protocol/multiplexing). It provides browsers with a
|
|
7
|
+
`braid_fetch()` drop-in replacement for the `fetch()` API, and offers nodejs
|
|
8
|
+
an `http` plugin, enabling simple Braid communication.
|
|
4
9
|
|
|
5
10
|
Developed in [braid.org](https://braid.org).
|
|
6
11
|
|
|
@@ -143,18 +148,17 @@ var braidify = require('braid-http').http_server
|
|
|
143
148
|
import {http_server as braidify} from 'braid-http'
|
|
144
149
|
|
|
145
150
|
require('http').createServer(
|
|
146
|
-
(req, res) => {
|
|
147
|
-
//
|
|
148
|
-
braidify(req, res)
|
|
151
|
+
braidify((req, res) => {
|
|
152
|
+
// Now braid stuff is available on req and res
|
|
149
153
|
|
|
150
|
-
//
|
|
154
|
+
// So you can easily handle subscriptions
|
|
151
155
|
if (req.subscribe)
|
|
152
156
|
res.startSubscription({ onClose: _=> null })
|
|
153
157
|
// startSubscription automatically sets statusCode = 209
|
|
154
158
|
else
|
|
155
159
|
res.statusCode = 200
|
|
156
160
|
|
|
157
|
-
//
|
|
161
|
+
// And send updates over a subscription
|
|
158
162
|
res.sendUpdate({
|
|
159
163
|
version: ['greg'],
|
|
160
164
|
body: JSON.stringify({greg: 'greg'})
|
|
@@ -165,8 +169,8 @@ require('http').createServer(
|
|
|
165
169
|
|
|
166
170
|
### Example Nodejs server with `require('express')`
|
|
167
171
|
|
|
168
|
-
|
|
169
|
-
added to every request and response.
|
|
172
|
+
Or if you're using `express`, you can just call `app.use(braidify)` to get
|
|
173
|
+
braid features added to every request and response.
|
|
170
174
|
|
|
171
175
|
```javascript
|
|
172
176
|
var braidify = require('braid-http').http_server
|
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
|