refactor: Prevent negated conditions

This commit is contained in:
Joachim Van Herwegen
2023-10-30 17:04:20 +01:00
parent c9e4c7041c
commit 98f5d8fb73
9 changed files with 28 additions and 30 deletions

View File

@@ -44,14 +44,14 @@ class WebSocketListener extends WebSocketListenerEmitter {
// Verify the WebSocket protocol version
const protocolHeader = headers['sec-websocket-protocol'];
if (!protocolHeader) {
this.sendMessage('warning', `Missing Sec-WebSocket-Protocol header, expected value '${VERSION}'`);
} else {
if (protocolHeader) {
const supportedProtocols = splitCommaSeparated(protocolHeader);
if (!supportedProtocols.includes(VERSION)) {
this.sendMessage('error', `Client does not support protocol ${VERSION}`);
this.stop();
}
} else {
this.sendMessage('warning', `Missing Sec-WebSocket-Protocol header, expected value '${VERSION}'`);
}
// Store the HTTP host and protocol