Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fa8b82d424 | |||
| 89e2a7da82 | |||
| 70ef5440c4 |
@@ -1,3 +1,7 @@
|
||||
### 0.6.2 / 2015-07-18
|
||||
|
||||
* When the peer sends a close frame with no error code, emit 1000
|
||||
|
||||
### 0.6.1 / 2015-07-13
|
||||
|
||||
* Use the `buffer.{read,write}UInt{16,32}BE` methods for reading/writing numbers
|
||||
|
||||
@@ -94,6 +94,7 @@ var instance = {
|
||||
},
|
||||
|
||||
ERROR_CODES: [1000, 1001, 1002, 1003, 1007, 1008, 1009, 1010, 1011],
|
||||
DEFAULT_ERROR_CODE: 1000,
|
||||
MIN_RESERVED_ERROR: 3000,
|
||||
MAX_RESERVED_ERROR: 4999,
|
||||
|
||||
@@ -403,7 +404,7 @@ var instance = {
|
||||
return this._emitMessage(this._message);
|
||||
|
||||
if (opcode === this.OPCODES.close) {
|
||||
code = (payload.length >= 2) ? 256 * payload[0] + payload[1] : null;
|
||||
code = (payload.length >= 2) ? payload.readUInt16BE(0) : null;
|
||||
reason = (payload.length > 2) ? this._encode(payload.slice(2)) : null;
|
||||
|
||||
if (!(payload.length === 0) &&
|
||||
@@ -414,7 +415,7 @@ var instance = {
|
||||
if (payload.length > 125 || (payload.length > 2 && !reason))
|
||||
code = this.ERRORS.protocol_error;
|
||||
|
||||
this._shutdown(code, reason || '');
|
||||
this._shutdown(code || this.DEFAULT_ERROR_CODE, reason || '');
|
||||
}
|
||||
|
||||
if (opcode === this.OPCODES.ping) {
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
, "keywords" : ["websocket"]
|
||||
, "license" : "MIT"
|
||||
|
||||
, "version" : "0.6.1"
|
||||
, "version" : "0.6.2"
|
||||
, "engines" : {"node": ">=0.6.0"}
|
||||
, "main" : "./lib/websocket/driver"
|
||||
, "dependencies" : {"websocket-extensions": ">=0.1.1"}
|
||||
|
||||
@@ -595,6 +595,34 @@ test.describe("Hybi", function() { with(this) {
|
||||
this.driver().parse([0x88, 0x04, 0x03, 0xe9, 0x4f, 0x4b])
|
||||
}})
|
||||
}})
|
||||
|
||||
describe("receiving a close frame with a too-short payload", function() { with(this) {
|
||||
before(function() {
|
||||
this.driver().parse([0x88, 0x01, 0x03])
|
||||
})
|
||||
|
||||
it("triggers the onclose event with a protocol error", function() { with(this) {
|
||||
assertEqual( [1002, ""], close )
|
||||
}})
|
||||
|
||||
it("changes the state to closed", function() { with(this) {
|
||||
assertEqual( "closed", driver().getState() )
|
||||
}})
|
||||
}})
|
||||
|
||||
describe("receiving a close frame with no code", function() { with(this) {
|
||||
before(function() { with(this) {
|
||||
this.driver().parse([0x88, 0x00])
|
||||
}})
|
||||
|
||||
it("triggers the onclose event with code 1000", function() { with(this) {
|
||||
assertEqual( [1000, ""], close )
|
||||
}})
|
||||
|
||||
it("changes the state to closed", function() { with(this) {
|
||||
assertEqual( "closed", driver().getState() )
|
||||
}})
|
||||
}})
|
||||
}})
|
||||
|
||||
describe("in the closed state", function() { with(this) {
|
||||
|
||||
Reference in New Issue
Block a user