braid-http 0.3.4 → 0.3.6
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 +21 -15
- package/package.json +1 -1
package/braid-http-client.js
CHANGED
|
@@ -168,7 +168,7 @@ async function braid_fetch (url, params = {}) {
|
|
|
168
168
|
if (params.subscribe)
|
|
169
169
|
params.headers.set('subscribe', 'true')
|
|
170
170
|
if (params.peer)
|
|
171
|
-
params.
|
|
171
|
+
params.headers.set('peer', params.peer)
|
|
172
172
|
|
|
173
173
|
// Prevent browsers from going to disk cache
|
|
174
174
|
params.cache = 'no-cache'
|
|
@@ -324,25 +324,24 @@ async function handle_fetch_stream (stream, cb) {
|
|
|
324
324
|
while (true) {
|
|
325
325
|
var versions = []
|
|
326
326
|
|
|
327
|
+
// Read the next chunk of stream!
|
|
327
328
|
try {
|
|
328
|
-
// Read the next chunk of stream!
|
|
329
329
|
var {done, value} = await reader.read()
|
|
330
|
-
|
|
331
|
-
// Check if this connection has been closed!
|
|
332
|
-
if (done) {
|
|
333
|
-
console.debug("Connection closed.")
|
|
334
|
-
cb(null, 'Connection closed')
|
|
335
|
-
return
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// Tell the parser to process some more stream
|
|
339
|
-
parser.read(decoder.decode(value))
|
|
340
330
|
}
|
|
341
|
-
|
|
342
331
|
catch (e) {
|
|
343
332
|
cb(null, e)
|
|
344
333
|
return
|
|
345
334
|
}
|
|
335
|
+
|
|
336
|
+
// Check if this connection has been closed!
|
|
337
|
+
if (done) {
|
|
338
|
+
console.debug("Connection closed.")
|
|
339
|
+
cb(null, 'Connection closed')
|
|
340
|
+
return
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Tell the parser to process some more stream
|
|
344
|
+
parser.read(decoder.decode(value))
|
|
346
345
|
}
|
|
347
346
|
}
|
|
348
347
|
|
|
@@ -368,9 +367,16 @@ var subscription_parser = (cb) => ({
|
|
|
368
367
|
|
|
369
368
|
// Now loop through the input and parse until we hit a dead end
|
|
370
369
|
while (this.state.input.trim() !== '') {
|
|
371
|
-
this.state = parse_update (this.state)
|
|
372
370
|
|
|
373
|
-
//
|
|
371
|
+
// Try to parse an update
|
|
372
|
+
try {
|
|
373
|
+
this.state = parse_update (this.state)
|
|
374
|
+
} catch (e) {
|
|
375
|
+
this.cb(null, e)
|
|
376
|
+
return
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// Maybe we parsed an update! That's cool!
|
|
374
380
|
if (this.state.result === 'success') {
|
|
375
381
|
this.cb({
|
|
376
382
|
version: this.state.version,
|