braid-http 1.3.64 → 1.3.66

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.
Files changed (2) hide show
  1. package/README.md +80 -5
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -139,15 +139,27 @@ for await (var update of subscription_iterator) {
139
139
 
140
140
  ## Using it in Nodejs
141
141
 
142
- ### Example Nodejs server with `require('http')`
142
+ You can braidify your nodejs server with:
143
+
144
+ ```
145
+ var braidify = require('braid-http').http_server
146
+ ```
147
+
148
+ Braidify adds these new abilities to requests and responses:
143
149
 
144
- Braidify adds these fields and methods to requests and responses:
145
150
  - `req.subscribe`
146
151
  - `req.startSubscription({onClose: cb})`
147
152
  - `await req.parseUpdate()`
148
153
  - `res.sendUpdate()`
149
154
 
150
- Use it like this:
155
+ You can call it in two ways:
156
+
157
+ 1. `braidify((req, res) => ...)` wraps your HTTP request handler, and gives it
158
+ perfectly braidified requests and responses.
159
+ 2. `braidify(req, res, next)` will add arguments to your existing requests and
160
+ responses. You can use this as express middleware.
161
+
162
+ ### Example Nodejs server with the built-in HTTP module
151
163
 
152
164
  ```javascript
153
165
  var braidify = require('braid-http').http_server
@@ -174,7 +186,23 @@ require('http').createServer(
174
186
  ).listen(9935)
175
187
  ```
176
188
 
177
- ### Example Nodejs server with `require('express')`
189
+ You can also use `braidify` within a request handler like this:
190
+
191
+ ```javascript
192
+ require('http').createServer(
193
+ (req, res) => {
194
+ braidify(req, res); if (req.is_multiplexer) return
195
+ // Now braid stuff is available on req and res
196
+
197
+ // ...
198
+ })
199
+ ).listen(9935)
200
+ ```
201
+
202
+ The `is_multiplexer` test in this form is only necessary if multiplexing is
203
+ enabled.
204
+
205
+ ### Example Nodejs server with Express
178
206
 
179
207
  Or if you're using `express`, you can just call `app.use(braidify)` to get
180
208
  braid features added to every request and response.
@@ -215,7 +243,6 @@ require('http').createServer(app).listen(8583)
215
243
  ```
216
244
 
217
245
 
218
-
219
246
  ### Example Nodejs client with `require('http')`
220
247
 
221
248
  ```javascript
@@ -285,3 +312,51 @@ fetch('https://localhost:3009/chat',
285
312
  x => console.log('Got ', x)
286
313
  )
287
314
  ```
315
+
316
+ ## Configuring Multiplexing
317
+
318
+ You shouldn't need to, but can, configure which requests the library will
319
+ [multiplex](https://braid.org/protocol/multiplexing). You can configure
320
+ multiplexing on both the client and the server. They both need multiplexing
321
+ enabled for it to happen.
322
+
323
+ ### Client
324
+
325
+ A client can globally disable multiplexing on `braid_fetch()` with:
326
+
327
+ ```javascript
328
+ braid_fetch.enable_multiplex = false
329
+ ```
330
+
331
+ It can enable multiplexing for all GET requests with:
332
+
333
+ ```javascript
334
+ braid_fetch.enable_multiplex = true
335
+ ```
336
+
337
+ It can also set it to multiplex after `N` connections to an origin with:
338
+
339
+ ```javascript
340
+ braid_fetch.enable_multiplex = {after: N}
341
+ ```
342
+
343
+ The default value is `{after: 1}`.
344
+
345
+ A client can override this global setting per-request by passing the same
346
+ value into `braid_fetch(url, {multiplex: <value>})`, such as with:
347
+
348
+ ```javascript
349
+ braid_fetch('/example', {multiplex: true, subscription: true})
350
+ braid_fetch('/example', {multiplex: false, subscription: true})
351
+ // or
352
+ braid_fetch('/example', {multiplex: {after: 1}, subscription: true})
353
+ ```
354
+
355
+ ### Server
356
+
357
+ Configure mutliplexing with:
358
+
359
+ ```javascript
360
+ var braidify = require('braid-http').http-server
361
+ nbraidify.enable_multiplex = true // or false
362
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "1.3.64",
3
+ "version": "1.3.66",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/server.js"