0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-24 02:07:30 +01:00

fix(websocket): prevent sending entire buffer when streaming Uint8Array chunks (#3570)

* fix(websocket): prevent full buffer send on Uint8Array chunks

* Fix formatting and line endings for CI compliance
This commit is contained in:
Ariel-Moroshko 2024-10-29 06:12:54 +02:00 committed by GitHub
parent a90db7c8dd
commit 745c2919b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 6 deletions

View File

@ -89,7 +89,7 @@ describe('WSContext', () => {
expect(nullURLWS.url).toBeNull()
})
it('Should normalize message in send()', () => {
let data: string | ArrayBuffer | null = null
let data: string | ArrayBuffer | Uint8Array | null = null
const wsContext = new WSContext({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
send(received, _options) {
@ -104,6 +104,6 @@ describe('WSContext', () => {
expect(data).toBeInstanceOf(ArrayBuffer)
wsContext.send(new Uint8Array(16))
expect(data).toBeInstanceOf(ArrayBuffer)
expect(data).toBeInstanceOf(Uint8Array)
})
})

View File

@ -68,10 +68,7 @@ export class WSContext<T = unknown> {
this.protocol = init.protocol ?? null
}
send(source: string | ArrayBuffer | Uint8Array, options?: SendOptions): void {
this.#init.send(
typeof source === 'string' ? source : source instanceof Uint8Array ? source.buffer : source,
options ?? {}
)
this.#init.send(source, options ?? {})
}
raw?: T
binaryType: BinaryType = 'arraybuffer'