Skip to content

Commit

Permalink
[fix] Allow close codes 1012 and 1013
Browse files Browse the repository at this point in the history
  • Loading branch information
SEAPUNK authored and lpinca committed Oct 15, 2016
1 parent a432e95 commit b58f688
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/ErrorCodes.js
Expand Up @@ -8,7 +8,7 @@

module.exports = {
isValidErrorCode: function (code) {
return (code >= 1000 && code <= 1011 && code !== 1004 && code !== 1005 && code !== 1006) ||
return (code >= 1000 && code <= 1013 && code !== 1004 && code !== 1005 && code !== 1006) ||
(code >= 3000 && code <= 4999);
},
1000: 'normal',
Expand All @@ -22,5 +22,7 @@ module.exports = {
1008: 'policy violation',
1009: 'message too big',
1010: 'extension handshake missing',
1011: 'an unexpected condition prevented the request from being fulfilled'
1011: 'an unexpected condition prevented the request from being fulfilled',
1012: 'service restart',
1013: 'try again later'
};
14 changes: 14 additions & 0 deletions test/WebSocket.test.js
Expand Up @@ -1538,6 +1538,20 @@ describe('WebSocket', function() {
});
});
});

it('allows close code 1013', function (done) {
var wss = new WebSocketServer({port: ++port}, function () {
var ws = new WebSocket(`ws://localhost:${port}`);
ws.on('close', function (code) {
assert.strictEqual(code, 1013);
wss.close(done);
});
});

wss.on('connection', function (ws) {
ws.close(1013);
});
});
});

describe('W3C API emulation', function() {
Expand Down

0 comments on commit b58f688

Please sign in to comment.