diff options
author | Matt Mastracci <matthew@mastracci.com> | 2024-04-18 11:21:25 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-18 11:21:25 -0600 |
commit | d9d3f81f291bbba4ab526f1781ca78e8a00cba64 (patch) | |
tree | d3b09207a9ea1108a0eadd998b46f0d39dada83b /tests/unit/fetch_test.ts | |
parent | 6a09a16d710b2d7a9d39478e5bcbabb40919d657 (diff) |
chore: remove unused, unstable 'http' namespace (#23436)
Landing parts of #21903 in preparation for the removal of serveHttp.
Diffstat (limited to 'tests/unit/fetch_test.ts')
-rw-r--r-- | tests/unit/fetch_test.ts | 38 |
1 files changed, 5 insertions, 33 deletions
diff --git a/tests/unit/fetch_test.ts b/tests/unit/fetch_test.ts index c33503bdf..3202d40fa 100644 --- a/tests/unit/fetch_test.ts +++ b/tests/unit/fetch_test.ts @@ -1249,44 +1249,16 @@ Deno.test({}, function fetchWritableRespProps() { Deno.test( { permissions: { net: true } }, - async function fetchFilterOutCustomHostHeader(): Promise< - void - > { + async function fetchFilterOutCustomHostHeader() { const addr = `127.0.0.1:${listenPort}`; - const [hostname, port] = addr.split(":"); - const listener = Deno.listen({ - hostname, - port: Number(port), - }) as Deno.Listener; - - let httpConn: Deno.HttpConn; - listener.accept().then(async (conn: Deno.Conn) => { - httpConn = Deno.serveHttp(conn); - - await httpConn.nextRequest() - .then(async (requestEvent: Deno.RequestEvent | null) => { - const hostHeader = requestEvent?.request.headers.get("Host"); - const headersToReturn = hostHeader - ? { "Host": hostHeader } - : undefined; - - await requestEvent?.respondWith( - new Response("", { - status: 200, - headers: headersToReturn, - }), - ); - }); + const server = Deno.serve({ port: listenPort }, (req) => { + return new Response(`Host header was ${req.headers.get("Host")}`); }); - const response = await fetch(`http://${addr}/`, { headers: { "Host": "example.com" }, }); - await response.text(); - listener.close(); - httpConn!.close(); - - assertEquals(response.headers.get("Host"), addr); + assertEquals(await response.text(), `Host header was ${addr}`); + await server.shutdown(); }, ); |