diff --git a/lib/server.js b/lib/server.js index 91d2b116e3..09ab49ca05 100644 --- a/lib/server.js +++ b/lib/server.js @@ -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' + diff --git a/test/server.js b/test/server.js index cef2b96b16..8cdfc9db8a 100644 --- a/test/server.js +++ b/test/server.js @@ -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 () {