Skip to content

Commit

Permalink
Close event socket after each message to support antivirus/firewalls …
Browse files Browse the repository at this point in the history
…such as Sophos
  • Loading branch information
Andre Rabold committed Feb 8, 2014
1 parent 79a9dab commit afc0f2e
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions lib/dashing.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports.Dashing = function Dashing() {
dashing.views = dashing.root + '/dashboards';
dashing.default_dashboard = null;
dashing.port = (process.env.PORT || 3030);
dashing.force_close_event_socket = false;

dashing.protected = function(req, res, next) {
next();
Expand Down Expand Up @@ -84,14 +85,17 @@ module.exports.Dashing = function Dashing() {
// let request last as long as possible
req.socket.setTimeout(0);

var conn = {
id: (new Date().getTime().toString() + Math.floor(Math.random() * 1000).toString()),
send: function(body) {
res.write(body);
res.flush(); // need to flush with .compress()
}
};
connections[conn.id] = conn;
if (!dashing.force_close_event_socket) {
// this won't be necessary if we close the connection after each data package
var conn = {
id: (new Date().getTime().toString() + Math.floor(Math.random() * 1000).toString()),
send: function(body) {
res.write(body);
res.flush(); // need to flush with .compress()
}
};
connections[conn.id] = conn;
}

// send headers for event-stream connection
res.writeHead(200, {
Expand All @@ -105,9 +109,14 @@ module.exports.Dashing = function Dashing() {
res.write(latest_events());
res.flush(); // need to flush with .compress()

req.on('close', function() {
delete connections[conn.id];
});
if (!dashing.force_close_event_socket) {
req.on('close', function() {
delete connections[conn.id];
});
}
else {
res.end();
}
});

app.get('/', function(req, res) {
Expand Down

0 comments on commit afc0f2e

Please sign in to comment.