Skip to content

Commit

Permalink
Correctly 404 upgrade requests for an unknown endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
DamonOehlman committed Oct 8, 2014
1 parent 57655b0 commit 72a089e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,24 @@ module.exports = function(server, opts) {
});
}

primus.transformer.on('previous::upgrade', function(req, socket, head) {
abortConnection(socket, 404, 'Not Found');
});

return require('./manager')(primus, opts);
};

function abortConnection(socket, code, name) {
try {
var response = [
'HTTP/1.1 ' + code + ' ' + name,
'Content-type: text/html'
];
socket.write(response.concat('', '').join('\r\n'));
}
catch (e) { /* ignore errors - we've aborted this connection */ }
finally {
// ensure that an early aborted connection is shut down completely
try { socket.destroy(); } catch (e) {}
}
}

0 comments on commit 72a089e

Please sign in to comment.