Skip to content

Commit

Permalink
[fix] Fix null payload when aborting connection (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Apr 28, 2017
1 parent 935b155 commit e76e035
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ Server.prototype.attach = function (server, options) {

function abortConnection (socket, code) {
if (socket.writable) {
var message = Server.errorMessages.hasOwnProperty(code) ? Server.errorMessages[code] : code;
var message = Server.errorMessages.hasOwnProperty(code) ? Server.errorMessages[code] : (code || '');
var length = Buffer.byteLength(message);
socket.write(
'HTTP/1.1 400 Bad Request\r\n' +
Expand Down
9 changes: 9 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ describe('server', function () {
});
});
});

it('should disallow connection that are rejected by `allowRequest`', function (done) {
listen({ allowRequest: function (req, fn) { fn(null, false); } }, function (port) {
var client = eioc('ws://localhost:%d'.s(port), { transports: ['websocket'] });
client.on('error', function () {
done();
});
});
});
});

describe('handshake', function () {
Expand Down

0 comments on commit e76e035

Please sign in to comment.