braid-http 1.3.9 → 1.3.10
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 +9 -5
- package/braid-http-server.js +6 -2
- package/package.json +1 -1
package/braid-http-client.js
CHANGED
|
@@ -162,9 +162,9 @@ async function braid_fetch (url, params = {}) {
|
|
|
162
162
|
|
|
163
163
|
// We provide some shortcuts for Braid params
|
|
164
164
|
if (params.version)
|
|
165
|
-
params.headers.set('version', params.version.map(JSON.stringify).join(', '))
|
|
165
|
+
params.headers.set('version', params.version.map(JSON.stringify).map(ascii_ify).join(', '))
|
|
166
166
|
if (Array.isArray(params.parents))
|
|
167
|
-
params.headers.set('parents', params.parents.map(JSON.stringify).join(', '))
|
|
167
|
+
params.headers.set('parents', params.parents.map(JSON.stringify).map(ascii_ify).join(', '))
|
|
168
168
|
if (params.subscribe)
|
|
169
169
|
params.headers.set('subscribe', 'true')
|
|
170
170
|
if (params.peer)
|
|
@@ -395,7 +395,7 @@ async function braid_fetch (url, params = {}) {
|
|
|
395
395
|
|
|
396
396
|
case 502: // Bad Gateway
|
|
397
397
|
case 504: // Gateway Timeout
|
|
398
|
-
give_up = false
|
|
398
|
+
give_up = false
|
|
399
399
|
}
|
|
400
400
|
if (give_up) {
|
|
401
401
|
let e = new Error(`giving up because of http status: ${res.status}${(res.status === 401 || res.status === 403) ? ` (access denied)` : ''}`)
|
|
@@ -578,12 +578,12 @@ function parse_update (state) {
|
|
|
578
578
|
function parse_headers (input) {
|
|
579
579
|
|
|
580
580
|
// Find the start of the headers
|
|
581
|
-
|
|
581
|
+
var start = 0
|
|
582
582
|
while (input[start] === 13 || input[start] === 10) start++
|
|
583
583
|
if (start === input.length) return {result: 'waiting'}
|
|
584
584
|
|
|
585
585
|
// Look for the double-newline at the end of the headers.
|
|
586
|
-
|
|
586
|
+
var end = start
|
|
587
587
|
while (++end) {
|
|
588
588
|
if (end > input.length) return {result: 'waiting'}
|
|
589
589
|
if ( input[end - 1] === 10
|
|
@@ -816,6 +816,10 @@ function deep_copy(x) {
|
|
|
816
816
|
return x
|
|
817
817
|
}
|
|
818
818
|
|
|
819
|
+
function ascii_ify(s) {
|
|
820
|
+
return s.replace(/[^\x20-\x7E]/g, c => '\\u' + c.charCodeAt(0).toString(16).padStart(4, '0'))
|
|
821
|
+
}
|
|
822
|
+
|
|
819
823
|
// ****************************
|
|
820
824
|
// Exports
|
|
821
825
|
// ****************************
|
package/braid-http-server.js
CHANGED
|
@@ -400,10 +400,10 @@ async function send_update(res, data, url, peer) {
|
|
|
400
400
|
// so we convert `value` from array to comma-separated strings.
|
|
401
401
|
if (header === 'version') {
|
|
402
402
|
header = 'Version' // Capitalize for prettiness
|
|
403
|
-
value = value.map(JSON.stringify).join(", ")
|
|
403
|
+
value = value.map(JSON.stringify).map(ascii_ify).join(", ")
|
|
404
404
|
} else if (header === 'parents') {
|
|
405
405
|
header = 'Parents' // Capitalize for prettiness
|
|
406
|
-
value = value.map(JSON.stringify).join(", ")
|
|
406
|
+
value = value.map(JSON.stringify).map(ascii_ify).join(", ")
|
|
407
407
|
}
|
|
408
408
|
|
|
409
409
|
// We don't output patches or body yet
|
|
@@ -447,4 +447,8 @@ function write_binary(res, body) {
|
|
|
447
447
|
res.write(body)
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
+
function ascii_ify(s) {
|
|
451
|
+
return s.replace(/[^\x20-\x7E]/g, c => '\\u' + c.charCodeAt(0).toString(16).padStart(4, '0'))
|
|
452
|
+
}
|
|
453
|
+
|
|
450
454
|
module.exports = braidify
|