diff options
Diffstat (limited to 'std/ws/mod.ts')
-rw-r--r-- | std/ws/mod.ts | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/std/ws/mod.ts b/std/ws/mod.ts index 9632fbbfb..7e444f274 100644 --- a/std/ws/mod.ts +++ b/std/ws/mod.ts @@ -8,7 +8,7 @@ import { Sha1 } from "../util/sha1.ts"; import { writeResponse } from "../http/io.ts"; import { TextProtoReader } from "../textproto/mod.ts"; import { Deferred, deferred } from "../util/async.ts"; -import { assertNotEOF } from "../testing/asserts.ts"; +import { assert } from "../testing/asserts.ts"; import { concat } from "../bytes/mod.ts"; import Conn = Deno.Conn; import Writer = Deno.Writer; @@ -149,7 +149,8 @@ export async function writeFrame( * @throws `Error` Frame is invalid */ export async function readFrame(buf: BufReader): Promise<WebSocketFrame> { - let b = assertNotEOF(await buf.readByte()); + let b = await buf.readByte(); + assert(b !== null); let isLastFrame = false; switch (b >>> 4) { case 0b1000: @@ -163,25 +164,28 @@ export async function readFrame(buf: BufReader): Promise<WebSocketFrame> { } const opcode = b & 0x0f; // has_mask & payload - b = assertNotEOF(await buf.readByte()); + b = await buf.readByte(); + assert(b !== null); const hasMask = b >>> 7; let payloadLength = b & 0b01111111; if (payloadLength === 126) { - const l = assertNotEOF(await readShort(buf)); + const l = await readShort(buf); + assert(l !== null); payloadLength = l; } else if (payloadLength === 127) { - const l = assertNotEOF(await readLong(buf)); + const l = await readLong(buf); + assert(l !== null); payloadLength = Number(l); } // mask let mask: Uint8Array | undefined; if (hasMask) { mask = new Uint8Array(4); - assertNotEOF(await buf.readFull(mask)); + assert((await buf.readFull(mask)) !== null); } // payload const payload = new Uint8Array(payloadLength); - assertNotEOF(await buf.readFull(payload)); + assert((await buf.readFull(payload)) !== null); return { isLastFrame, opcode, @@ -479,7 +483,7 @@ export async function handshake( const tpReader = new TextProtoReader(bufReader); const statusLine = await tpReader.readLine(); - if (statusLine === Deno.EOF) { + if (statusLine === null) { throw new Deno.errors.UnexpectedEof(); } const m = statusLine.match(/^(?<version>\S+) (?<statusCode>\S+) /); @@ -497,7 +501,7 @@ export async function handshake( } const responseHeaders = await tpReader.readMIMEHeader(); - if (responseHeaders === Deno.EOF) { + if (responseHeaders === null) { throw new Deno.errors.UnexpectedEof(); } |