braid-http 0.2.0 → 0.3.1

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.
@@ -154,8 +154,8 @@ async function braid_fetch (url, params = {}) {
154
154
 
155
155
  // We provide some shortcuts for Braid params
156
156
  if (params.version)
157
- params.headers.set('version', JSON.stringify(params.version))
158
- if (params.parents)
157
+ params.headers.set('version', params.version.map(JSON.stringify).join(', '))
158
+ if (params.parents?.length)
159
159
  params.headers.set('parents', params.parents.map(JSON.stringify).join(', '))
160
160
  if (params.subscribe)
161
161
  params.headers.set('subscribe', 'true')
@@ -487,9 +487,8 @@ function parse_headers (input) {
487
487
 
488
488
  // Success! Let's parse special headers
489
489
  if ('version' in headers)
490
- headers.version = JSON.parse(headers.version)
491
- if ('parents' in headers)
492
- headers.parents = JSON.parse('['+headers.parents+']')
490
+ headers.version = JSON.parse('['+headers.version+']')
491
+ headers.parents = JSON.parse('['+(headers.parents ?? '')+']')
493
492
  if ('patches' in headers)
494
493
  headers.patches = JSON.parse(headers.patches)
495
494
 
@@ -195,8 +195,8 @@ function braidify (req, res, next) {
195
195
  res.setHeader('Range-Request-Allow-Units', 'json')
196
196
 
197
197
  // Extract braid info from headers
198
- var version = req.headers.version && JSON.parse(req.headers.version),
199
- parents = req.headers.parents && JSON.parse('['+req.headers.parents+']'),
198
+ var version = JSON.parse('['+(req.headers.version ?? '')+']'),
199
+ parents = JSON.parse('['+(req.headers.parents ?? '')+']'),
200
200
  peer = req.headers['peer'],
201
201
  url = req.url.substr(1)
202
202
 
@@ -335,10 +335,11 @@ function send_version(res, data, url, peer) {
335
335
  // Version and Parents get output in the Structured Headers format
336
336
  if (header === 'version') {
337
337
  header = 'Version' // Capitalize for prettiness
338
- value = JSON.stringify(value)
338
+ value = value.map(JSON.stringify).join(", ")
339
339
  } else if (header === 'parents') {
340
340
  header = 'Parents' // Capitalize for prettiness
341
- value = parents.map(JSON.stringify).join(", ")
341
+ if (value.length == 0) continue // we express no parents as not having the field at all
342
+ value = value.map(JSON.stringify).join(", ")
342
343
  }
343
344
 
344
345
  // We don't output patches or body yet
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/server.js"
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Braid-HTTP
2
2
 
3
- This polyfill library implements the [Braid-HTTP v03 protocol](https://github.com/braid-org/braid-spec/blob/master/draft-toomim-httpbis-braid-http-03.txt) in Javascript. It gives browsers a `braid_fetch()` drop-in replacement for the `fetch()` API, and gives nodejs an `http` plugin, allowing them to speak Braid in a simple way.
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) in Javascript. It gives browsers a `braid_fetch()` drop-in replacement for the `fetch()` API, and gives nodejs an `http` plugin, allowing them to speak Braid in a simple way.
4
4
 
5
5
  Developed in [braid.org](https://braid.org).
6
6