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 CHANGED
@@ -1,6 +1,18 @@
1
1
  # Braid-HTTP
2
2
 
3
- This polyfill library implements the [Braid-HTTP v04 protocol](https://github.com/braid-org/braid-spec/blob/master/draft-toomim-httpbis-braid-http-04.txt), modified slightly to follow the HTTP Multiresponse concept discussed at [braid.org/meeting-89](https://braid.org/meeting-89). It provides browsers with a `braid_fetch()` drop-in replacement for the `fetch()` API, and offers nodejs an `http` plugin, enabling simple Braid communication.
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
- // Add braid stuff to req and res
148
- braidify(req, res)
158
+ braidify((req, res) => {
159
+ // Now braid stuff is available on req and res
149
160
 
150
- // Now use it
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
- // Send the current version
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
- With `express`, you can simply call `app.use(braidify)` to get braid features
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` library (below) for requests on nodejs instead.
294
+ using the `http` client on nodejs instead.
@@ -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) 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 (!multiplex_fetch.multiplexers[mux_key]) multiplex_fetch.multiplexers[mux_key] =
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "1.3.58",
3
+ "version": "1.3.60",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/server.js"