braid-http 1.3.62 → 1.3.64
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 +4 -4
- package/braid-http-server.js +12 -3
- package/package.json +1 -1
package/braid-http-client.js
CHANGED
|
@@ -882,11 +882,11 @@ async function promise_done(promise) {
|
|
|
882
882
|
}
|
|
883
883
|
|
|
884
884
|
function random_base64url(n) {
|
|
885
|
-
var buf = new Uint8Array(n)
|
|
886
|
-
var crypt = (typeof crypto !== 'undefined') ? crypto : require('crypto')
|
|
887
885
|
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
|
|
888
|
-
|
|
889
|
-
|
|
886
|
+
var result = ''
|
|
887
|
+
for (let i = 0; i < n; i++)
|
|
888
|
+
result += chars[Math.floor(Math.random() * 64)]
|
|
889
|
+
return result
|
|
890
890
|
}
|
|
891
891
|
|
|
892
892
|
|
package/braid-http-server.js
CHANGED
|
@@ -561,7 +561,12 @@ function braidify (req, res, next) {
|
|
|
561
561
|
res.on('finish', x => disconnected('finish'))
|
|
562
562
|
req.on('abort', x => disconnected('abort'))
|
|
563
563
|
|
|
564
|
-
//
|
|
564
|
+
// Start sending heartbeats to the client every N seconds if
|
|
565
|
+
// they've been requested. Heartbeats help a client know if a
|
|
566
|
+
// connection is still alive, and can also signal to
|
|
567
|
+
// intermediaries to keep a connection open, because sometimes
|
|
568
|
+
// intermediaries will time-out a connection after a period of no
|
|
569
|
+
// activity.
|
|
565
570
|
if (req.headers['heartbeats']) {
|
|
566
571
|
let heartbeats = parseFloat(req.headers['heartbeats'])
|
|
567
572
|
if (isFinite(heartbeats)) {
|
|
@@ -570,8 +575,12 @@ function braidify (req, res, next) {
|
|
|
570
575
|
res.on('close', () => closed = true)
|
|
571
576
|
loop()
|
|
572
577
|
function loop() {
|
|
573
|
-
|
|
574
|
-
|
|
578
|
+
// We only send heartbeats:
|
|
579
|
+
// - After the headers have been sent
|
|
580
|
+
// - Before the stream has closed
|
|
581
|
+
if (res.headersSent && !res.writableEnded && !closed)
|
|
582
|
+
res.write("\r\n")
|
|
583
|
+
|
|
575
584
|
setTimeout(loop, 1000 * heartbeats)
|
|
576
585
|
}
|
|
577
586
|
}
|