diff --git a/lib/web/websocket/receiver.js b/lib/web/websocket/receiver.js index 2638abe3bfd..dac9122a408 100644 --- a/lib/web/websocket/receiver.js +++ b/lib/web/websocket/receiver.js @@ -15,7 +15,6 @@ const { isContinuationFrame } = require('./util') const { WebsocketFrameSend } = require('./frame') -const { closeWebSocketConnection } = require('./connection') const { PerMessageDeflate } = require('./permessage-deflate') // This code was influenced by ws released under the MIT license. @@ -225,7 +224,7 @@ class ByteParser extends Writable { } else { this.#extensions.get('permessage-deflate').decompress(body, this.#info.fin, (error, data) => { if (error) { - closeWebSocketConnection(this.#handler, 1007, error.message) + failWebsocketConnection(this.#handler, 1007, error.message) return } diff --git a/lib/web/websocket/stream/websocketstream.js b/lib/web/websocket/stream/websocketstream.js index bd426f6af7a..fe6a6fba551 100644 --- a/lib/web/websocket/stream/websocketstream.js +++ b/lib/web/websocket/stream/websocketstream.js @@ -50,7 +50,7 @@ class WebSocketStream { onConnectionEstablished: (response, extensions) => this.#onConnectionEstablished(response, extensions), onFail: (reason) => this.#onFail(reason), onMessage: (opcode, data) => this.#onMessage(opcode, data), - onParserError: (err) => {}, // eslint-disable-line + onParserError: (err) => failWebsocketConnection(this.#handler, null, err.message), onParserDrain: () => this.#handler.socket.resume(), onSocketData: (chunk) => { if (!this.#parser.write(chunk)) { diff --git a/lib/web/websocket/websocket.js b/lib/web/websocket/websocket.js index e04c6b6f921..584ead55a5d 100644 --- a/lib/web/websocket/websocket.js +++ b/lib/web/websocket/websocket.js @@ -61,7 +61,7 @@ class WebSocket extends EventTarget { onConnectionEstablished: (response, extensions) => this.#onConnectionEstablished(response, extensions), onFail: (code, reason) => this.#onFail(code, reason), onMessage: (opcode, data) => this.#onMessage(opcode, data), - onParserError: (err) => this.#onParserError(err), + onParserError: (err) => failWebsocketConnection(this.#handler, null, err.message), onParserDrain: () => this.#onParserDrain(), onSocketData: (chunk) => { if (!this.#parser.write(chunk)) { @@ -529,22 +529,6 @@ class WebSocket extends EventTarget { }) } - #onParserError (err) { - let message - let code - - if (err instanceof CloseEvent) { - message = err.reason - code = err.code - } else { - message = err.message - } - - fireEvent('error', this, () => new ErrorEvent('error', { error: err, message })) - - closeWebSocketConnection(this.#handler, code, null) - } - #onParserDrain () { this.#handler.socket.resume() }