Skip to content

Commit

Permalink
websocket: move codeblock in parseCloseBody (#3215)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed May 7, 2024
1 parent 5a79dec commit 8c3d42a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/web/websocket/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ class ByteParser extends Writable {
code = data.readUInt16BE(0)
}

if (code !== undefined && !isValidStatusCode(code)) {
return { code: 1002, reason: 'Invalid status code', error: true }
}

// https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.6
/** @type {Buffer} */
let reason = data.subarray(2)
Expand All @@ -323,10 +327,6 @@ class ByteParser extends Writable {
reason = reason.subarray(3)
}

if (code !== undefined && !isValidStatusCode(code)) {
return { code: 1002, reason: 'Invalid status code', error: true }
}

try {
reason = utf8Decode(reason)
} catch {
Expand Down

0 comments on commit 8c3d42a

Please sign in to comment.