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:
parent
a90db7c8dd
commit
745c2919b6
@ -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)
|
||||
})
|
||||
})
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user