braid-http 1.3.64 → 1.3.65

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 +81 -4
  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,6 +243,7 @@ require('http').createServer(app).listen(8583)
215
243
  ```
216
244
 
217
245
 
246
+ ```javascript
218
247
 
219
248
  ### Example Nodejs client with `require('http')`
220
249
 
@@ -285,3 +314,51 @@ fetch('https://localhost:3009/chat',
285
314
  x => console.log('Got ', x)
286
315
  )
287
316
  ```
317
+
318
+ ## Configuring Multiplexing
319
+
320
+ You shouldn't need to, but can, configure which requests the library will
321
+ [multiplex](https://braid.org/protocol/multiplexing). You can configure
322
+ multiplexing on both the client and the server. They both need multiplexing
323
+ enabled for it to happen.
324
+
325
+ ### Client
326
+
327
+ A client can globally disable multiplexing on `braid_fetch()` with:
328
+
329
+ ```javascript
330
+ braid_fetch.enable_multiplex = false
331
+ ```
332
+
333
+ It can enable multiplexing for all GET requests with:
334
+
335
+ ```javascript
336
+ braid_fetch.enable_multiplex = true
337
+ ```
338
+
339
+ It can also set it to multiplex after `N` connections to an origin with:
340
+
341
+ ```javascript
342
+ braid_fetch.enable_multiplex = {after: N}
343
+ ```
344
+
345
+ The default value is `{after: 1}`.
346
+
347
+ A client can override this global setting per-request by passing the same
348
+ value into `braid_fetch(url, {multiplex: <value>})`, such as with:
349
+
350
+ ```javascript
351
+ braid_fetch('/example', {multiplex: true, subscription: true})
352
+ braid_fetch('/example', {multiplex: false, subscription: true})
353
+ // or
354
+ braid_fetch('/example', {multiplex: {after: 1}, subscription: true})
355
+ ```
356
+
357
+ ### Server
358
+
359
+ Configure mutliplexing with:
360
+
361
+ ```javascript
362
+ var braidify = require('braid-http').http-server
363
+ nbraidify.enable_multiplex = true // or false
364
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "1.3.64",
3
+ "version": "1.3.65",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/server.js"