From f3bde1d53b4710fb526286e27af29a55f5da18c7 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Wed, 24 Aug 2022 14:10:57 +0200 Subject: feat(ext/flash): split upgradeHttp into two APIs (#15557) This commit splits `Deno.upgradeHttp` into two different APIs, because the same API is currently overloaded with two different functions. Flash requests upgrade immediately, with no need to return a `Response` object. Instead you have to manually write the response to the socket. Hyper requests only upgrade once a `Response` object has been sent. These two behaviours are now split into `Deno.upgradeHttp` and `Deno.upgradeHttpRaw`. The latter is flash only. The former only supports hyper requests at the moment, but can be updated to support flash in the future. Additionally this removes `void | Promise` as valid return types for the handler function. If one wants to use `Deno.upgradeHttpRaw`, they will have to type cast the handler signature - the signature is meant for the 99.99%, and should not be complicated for the 0.01% that use `Deno.upgradeHttpRaw()`. --- cli/tests/unit/flash_test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'cli/tests/unit') diff --git a/cli/tests/unit/flash_test.ts b/cli/tests/unit/flash_test.ts index f59484291..c718c1b2e 100644 --- a/cli/tests/unit/flash_test.ts +++ b/cli/tests/unit/flash_test.ts @@ -1002,14 +1002,14 @@ Deno.test( }, ); -Deno.test("upgradeHttp tcp", async () => { +Deno.test("upgradeHttpRaw tcp", async () => { const promise = deferred(); const listeningPromise = deferred(); const promise2 = deferred(); const ac = new AbortController(); const signal = ac.signal; const handler = async (req: Request) => { - const [conn, _] = await Deno.upgradeHttp(req); + const [conn, _] = Deno.upgradeHttpRaw(req); await conn.write( new TextEncoder().encode("HTTP/1.1 101 Switching Protocols\r\n\r\n"), @@ -1028,6 +1028,8 @@ Deno.test("upgradeHttp tcp", async () => { conn.close(); }; const server = Deno.serve({ + // NOTE: `as any` is used to bypass type checking for the return value + // of the handler. handler: handler as any, port: 4501, signal, -- cgit v1.2.3