Skip to content

Commit e76e035

Browse files
[fix] Fix null payload when aborting connection (#503)
1 parent 935b155 commit e76e035

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ Server.prototype.attach = function (server, options) {
503503

504504
function abortConnection (socket, code) {
505505
if (socket.writable) {
506-
var message = Server.errorMessages.hasOwnProperty(code) ? Server.errorMessages[code] : code;
506+
var message = Server.errorMessages.hasOwnProperty(code) ? Server.errorMessages[code] : (code || '');
507507
var length = Buffer.byteLength(message);
508508
socket.write(
509509
'HTTP/1.1 400 Bad Request\r\n' +

test/server.js

+9
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ describe('server', function () {
9292
});
9393
});
9494
});
95+
96+
it('should disallow connection that are rejected by `allowRequest`', function (done) {
97+
listen({ allowRequest: function (req, fn) { fn(null, false); } }, function (port) {
98+
var client = eioc('ws://localhost:%d'.s(port), { transports: ['websocket'] });
99+
client.on('error', function () {
100+
done();
101+
});
102+
});
103+
});
95104
});
96105

97106
describe('handshake', function () {

0 commit comments

Comments
 (0)