braid-http 0.3.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.
- package/braid-http-client.js +2 -3
- package/braid-http-server.js +3 -2
- package/package.json +1 -1
package/braid-http-client.js
CHANGED
|
@@ -155,7 +155,7 @@ async function braid_fetch (url, params = {}) {
|
|
|
155
155
|
// We provide some shortcuts for Braid params
|
|
156
156
|
if (params.version)
|
|
157
157
|
params.headers.set('version', params.version.map(JSON.stringify).join(', '))
|
|
158
|
-
if (params.parents)
|
|
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')
|
|
@@ -488,8 +488,7 @@ function parse_headers (input) {
|
|
|
488
488
|
// Success! Let's parse special headers
|
|
489
489
|
if ('version' in headers)
|
|
490
490
|
headers.version = JSON.parse('['+headers.version+']')
|
|
491
|
-
|
|
492
|
-
headers.parents = JSON.parse('['+headers.parents+']')
|
|
491
|
+
headers.parents = JSON.parse('['+(headers.parents ?? '')+']')
|
|
493
492
|
if ('patches' in headers)
|
|
494
493
|
headers.patches = JSON.parse(headers.patches)
|
|
495
494
|
|
package/braid-http-server.js
CHANGED
|
@@ -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 =
|
|
199
|
-
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
|
|
|
@@ -338,6 +338,7 @@ function send_version(res, data, url, peer) {
|
|
|
338
338
|
value = value.map(JSON.stringify).join(", ")
|
|
339
339
|
} else if (header === 'parents') {
|
|
340
340
|
header = 'Parents' // Capitalize for prettiness
|
|
341
|
+
if (value.length == 0) continue // we express no parents as not having the field at all
|
|
341
342
|
value = value.map(JSON.stringify).join(", ")
|
|
342
343
|
}
|
|
343
344
|
|