braid-http
Advanced tools
Comparing version
@@ -564,3 +564,8 @@ var assert = require('assert') | ||
// Heartbeats | ||
// Start sending heartbeats to the client every N seconds if | ||
// they've been requested. Heartbeats help a client know if a | ||
// connection is still alive, and can also signal to | ||
// intermediaries to keep a connection open, because sometimes | ||
// intermediaries will time-out a connection after a period of no | ||
// activity. | ||
if (req.headers['heartbeats']) { | ||
@@ -574,4 +579,8 @@ let heartbeats = parseFloat(req.headers['heartbeats']) | ||
function loop() { | ||
if (res.writableEnded || closed) return | ||
res.write("\r\n") | ||
// We only send heartbeats: | ||
// - After the headers have been sent | ||
// - Before the stream has closed | ||
if (res.headersSent && !res.writableEnded && !closed) | ||
res.write("\r\n") | ||
setTimeout(loop, 1000 * heartbeats) | ||
@@ -578,0 +587,0 @@ } |
{ | ||
"name": "braid-http", | ||
"version": "1.3.63", | ||
"version": "1.3.64", | ||
"description": "An implementation of Braid-HTTP for Node.js and Browsers", | ||
@@ -5,0 +5,0 @@ "scripts": { |
89241
0.63%1751
0.46%