@@ -110,6 +110,7 @@ class ByteParser extends Writable {
110
110
111
111
if ( isControlFrame ( opcode ) ) {
112
112
const loop = this . parseControlFrame ( callback , {
113
+ header : buffer ,
113
114
opcode,
114
115
fragmented,
115
116
payloadLength
@@ -122,6 +123,7 @@ class ByteParser extends Writable {
122
123
}
123
124
} else if ( isContinuationFrame ( opcode ) ) {
124
125
const loop = this . parseContinuationFrame ( callback , {
126
+ header : buffer ,
125
127
fin,
126
128
fragmented,
127
129
payloadLength
@@ -297,7 +299,7 @@ class ByteParser extends Writable {
297
299
* Parses control frames.
298
300
* @param {Buffer } data
299
301
* @param {(err?: Error) => void } callback
300
- * @param {{ opcode: number, fragmented: boolean, payloadLength: number } } info
302
+ * @param {{ opcode: number, fragmented: boolean, payloadLength: number, header: Buffer } } info
301
303
*/
302
304
parseControlFrame ( callback , info ) {
303
305
assert ( ! info . fragmented )
@@ -307,6 +309,9 @@ class ByteParser extends Writable {
307
309
failWebsocketConnection ( this . ws , 'Payload length for control frame exceeded 125 bytes.' )
308
310
return false
309
311
} else if ( this . #byteOffset < info . payloadLength ) {
312
+ this . #buffers. unshift ( info . header )
313
+ this . #byteOffset += 2
314
+
310
315
callback ( )
311
316
return false
312
317
}
@@ -405,14 +410,17 @@ class ByteParser extends Writable {
405
410
* Parses continuation frames.
406
411
* @param {Buffer } data
407
412
* @param {(err?: Error) => void } callback
408
- * @param {{ fin: boolean, fragmented: boolean, payloadLength: number } } info
413
+ * @param {{ fin: boolean, fragmented: boolean, payloadLength: number, header: Buffer } } info
409
414
*/
410
415
parseContinuationFrame ( callback , info ) {
411
416
// If we received a continuation frame before we started parsing another frame.
412
417
if ( this . #info. opcode === undefined ) {
413
418
failWebsocketConnection ( this . ws , 'Received unexpected continuation frame.' )
414
419
return false
415
420
} else if ( this . #byteOffset < info . payloadLength ) {
421
+ this . #buffers. unshift ( info . header )
422
+ this . #byteOffset += 2
423
+
416
424
callback ( )
417
425
return false
418
426
}
0 commit comments