Skip to content

Commit

Permalink
Change 'invalid' data payload error code to 'unsupported'
Browse files Browse the repository at this point in the history
It's not technically invalid - the standard does not disallow the length
that's used - it's just that this specific endpoint won't accept it.
  • Loading branch information
pimterry committed Jun 15, 2021
1 parent 12e9995 commit adc6a13
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
13 changes: 8 additions & 5 deletions doc/ws.md
Expand Up @@ -45,7 +45,7 @@
- [websocket.url](#websocketurl)
- [WebSocket.createWebSocketStream(websocket[, options])](#websocketcreatewebsocketstreamwebsocket-options)
- [WS Error Codes](#ws-error-codes)
- [WS_ERR_INVALID_DATA_PAYLOAD_LENGTH](#wserrinvaliddatapayloadlength)
- [WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH](#wserrunsupporteddatapayloadlength)
- [WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH](#wserrinvalidcontrolpayloadlength)
- [WS_ERR_INVALID_UTF8](#wserrinvalidutf8)
- [WS_ERR_INVALID_OPCODE](#wserrinvalidopcode)
Expand Down Expand Up @@ -309,7 +309,8 @@ human-readable string explaining why the connection has been closed.

- `error` {Error}

Emitted when an error occurs. Errors may have a `.code` property, matching one of the string values defined below under [WS Error Codes](#ws-error-codes).
Emitted when an error occurs. Errors may have a `.code` property, matching one
of the string values defined below under [WS Error Codes](#ws-error-codes).

### Event: 'message'

Expand Down Expand Up @@ -506,11 +507,13 @@ given `WebSocket`.

## WS Error Codes

Errors emitted by the websocket may have a `.code` property, describing the specific type of error that has occurred:
Errors emitted by the websocket may have a `.code` property, describing the
specific type of error that has occurred:

### WS_ERR_INVALID_DATA_PAYLOAD_LENGTH
### WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH

A data frame with an unexpectedly long payload was received.
A data frame was received with a payload longer than the maximum supported
payload of this endpoint.

### WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH

Expand Down
2 changes: 1 addition & 1 deletion lib/permessage-deflate.js
Expand Up @@ -495,7 +495,7 @@ function inflateOnData(chunk) {
}

this[kError] = new RangeError('Max payload size exceeded');
this[kError].code = 'WS_ERR_INVALID_DATA_PAYLOAD_LENGTH';
this[kError].code = 'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH';
this[kError][kStatusCode] = 1009;
this.removeListener('data', inflateOnData);
this.reset();
Expand Down
6 changes: 3 additions & 3 deletions lib/receiver.js
Expand Up @@ -347,7 +347,7 @@ class Receiver extends Writable {
'Unsupported WebSocket frame: payload length > 2^53 - 1',
false,
1009,
'WS_ERR_INVALID_DATA_PAYLOAD_LENGTH'
'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH'
);
}

Expand All @@ -371,7 +371,7 @@ class Receiver extends Writable {
'Max payload size exceeded',
false,
1009,
'WS_ERR_INVALID_DATA_PAYLOAD_LENGTH'
'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH'
);
}
}
Expand Down Expand Up @@ -457,7 +457,7 @@ class Receiver extends Writable {
'Max payload size exceeded',
false,
1009,
'WS_ERR_INVALID_DATA_PAYLOAD_LENGTH'
'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH'
)
);
}
Expand Down
8 changes: 4 additions & 4 deletions test/receiver.test.js
Expand Up @@ -748,7 +748,7 @@ describe('Receiver', () => {

receiver.on('error', (err) => {
assert.ok(err instanceof RangeError);
assert.strictEqual(err.code, 'WS_ERR_INVALID_DATA_PAYLOAD_LENGTH');
assert.strictEqual(err.code, 'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH');
assert.strictEqual(
err.message,
'Unsupported WebSocket frame: payload length > 2^53 - 1'
Expand Down Expand Up @@ -879,7 +879,7 @@ describe('Receiver', () => {

receiver.on('error', (err) => {
assert.ok(err instanceof RangeError);
assert.strictEqual(err.code, 'WS_ERR_INVALID_DATA_PAYLOAD_LENGTH');
assert.strictEqual(err.code, 'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH');
assert.strictEqual(err.message, 'Max payload size exceeded');
assert.strictEqual(err[kStatusCode], 1009);
done();
Expand All @@ -904,7 +904,7 @@ describe('Receiver', () => {

receiver.on('error', (err) => {
assert.ok(err instanceof RangeError);
assert.strictEqual(err.code, 'WS_ERR_INVALID_DATA_PAYLOAD_LENGTH');
assert.strictEqual(err.code, 'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH');
assert.strictEqual(err.message, 'Max payload size exceeded');
assert.strictEqual(err[kStatusCode], 1009);
done();
Expand Down Expand Up @@ -934,7 +934,7 @@ describe('Receiver', () => {

receiver.on('error', (err) => {
assert.ok(err instanceof RangeError);
assert.strictEqual(err.code, 'WS_ERR_INVALID_DATA_PAYLOAD_LENGTH');
assert.strictEqual(err.code, 'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH');
assert.strictEqual(err.message, 'Max payload size exceeded');
assert.strictEqual(err[kStatusCode], 1009);
done();
Expand Down

0 comments on commit adc6a13

Please sign in to comment.