braid-http 1.3.9 → 1.3.11

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.
@@ -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
- let start = 0;
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
- let end = start;
586
+ var end = start
587
587
  while (++end) {
588
588
  if (end > input.length) return {result: 'waiting'}
589
589
  if ( input[end - 1] === 10
@@ -592,7 +592,7 @@ function parse_headers (input) {
592
592
  }
593
593
 
594
594
  // Extract the header string
595
- var headers_source = new TextDecoder('utf-8').decode(new Uint8Array(input.slice(start, end)))
595
+ var headers_source = input.slice(start, end).map(x => String.fromCharCode(x)).join('')
596
596
 
597
597
  // Convert "HTTP 200 OK" to a :status: 200 header
598
598
  headers_source = headers_source.replace(/^HTTP\/?\d*\.?\d* (\d\d\d).*\r?\n/, ':status: $1\r\n')
@@ -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
  // ****************************
@@ -150,7 +150,7 @@ function parse_update (req, cb) {
150
150
  }
151
151
 
152
152
  // Extract the header string
153
- let headers_source = new TextDecoder('utf-8').decode(new Uint8Array(buffer.slice(s, e)))
153
+ let headers_source = buffer.slice(s, e).map(x => String.fromCharCode(x)).join('')
154
154
 
155
155
  // Now let's parse those headers.
156
156
  var headers = require('parse-headers')(headers_source)
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "1.3.9",
3
+ "version": "1.3.11",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/server.js"