mirror of
https://github.com/denoland/deno.git
synced 2024-11-30 16:40:57 -05:00
f3bde1d53b
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<void>` 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()`.
10 lines
300 B
JavaScript
10 lines
300 B
JavaScript
const { serve, upgradeHttpRaw } = Deno;
|
|
const u8 = Deno.core.encode("HTTP/1.1 101 Switching Protocols\r\n\r\n");
|
|
|
|
async function handler(req) {
|
|
const [conn, _firstPacket] = upgradeHttpRaw(req);
|
|
await conn.write(u8);
|
|
await conn.close();
|
|
}
|
|
|
|
serve(handler, { hostname: "127.0.0.1", port: 9000 });
|