diff options
Diffstat (limited to 'cli/tests/unit/http_test.ts')
-rw-r--r-- | cli/tests/unit/http_test.ts | 157 |
1 files changed, 0 insertions, 157 deletions
diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts index 7d1f8997d..bd4c8da09 100644 --- a/cli/tests/unit/http_test.ts +++ b/cli/tests/unit/http_test.ts @@ -1,7 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import { Buffer, BufReader, BufWriter } from "../../../test_util/std/io/mod.ts"; import { TextProtoReader } from "../testdata/run/textproto.ts"; -import { serve, serveTls } from "../../../test_util/std/http/server.ts"; import { assert, assertEquals, @@ -2181,162 +2180,6 @@ Deno.test({ }, }); -Deno.test("upgradeHttp tcp", async () => { - async function client() { - const tcpConn = await Deno.connect({ port: listenPort }); - await tcpConn.write( - new TextEncoder().encode( - "CONNECT server.example.com:80 HTTP/1.1\r\n\r\nbla bla bla\nbla bla\nbla\n", - ), - ); - setTimeout(async () => { - await tcpConn.write( - new TextEncoder().encode( - "bla bla bla\nbla bla\nbla\n", - ), - ); - tcpConn.close(); - }, 500); - } - - const abortController = new AbortController(); - const signal = abortController.signal; - - const server = serve((req) => { - const p = Deno.upgradeHttp(req); - - (async () => { - const [conn, firstPacket] = await p; - const buf = new Uint8Array(1024); - const firstPacketText = new TextDecoder().decode(firstPacket); - assertEquals(firstPacketText, "bla bla bla\nbla bla\nbla\n"); - const n = await conn.read(buf); - assert(n != null); - const secondPacketText = new TextDecoder().decode(buf.slice(0, n)); - assertEquals(secondPacketText, "bla bla bla\nbla bla\nbla\n"); - abortController.abort(); - conn.close(); - })(); - - return new Response(null, { status: 101 }); - }, { port: listenPort, signal }); - - await Promise.all([server, client()]); -}); - -Deno.test( - "upgradeHttp tls", - { permissions: { net: true, read: true } }, - async () => { - async function client() { - const caCerts = [ - await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem"), - ]; - const tlsConn = await Deno.connectTls({ - hostname: "localhost", - port: listenPort, - caCerts, - }); - await tlsConn.write( - new TextEncoder().encode( - "CONNECT server.example.com:80 HTTP/1.1\r\n\r\nbla bla bla\nbla bla\nbla\n", - ), - ); - setTimeout(async () => { - await tlsConn.write( - new TextEncoder().encode( - "bla bla bla\nbla bla\nbla\n", - ), - ); - tlsConn.close(); - }, 500); - } - - const abortController = new AbortController(); - const signal = abortController.signal; - const certFile = "cli/tests/testdata/tls/localhost.crt"; - const keyFile = "cli/tests/testdata/tls/localhost.key"; - - const server = serveTls((req) => { - const p = Deno.upgradeHttp(req); - - (async () => { - const [conn, firstPacket] = await p; - const buf = new Uint8Array(1024); - const firstPacketText = new TextDecoder().decode(firstPacket); - assertEquals(firstPacketText, "bla bla bla\nbla bla\nbla\n"); - const n = await conn.read(buf); - assert(n != null); - const secondPacketText = new TextDecoder().decode(buf.slice(0, n)); - assertEquals(secondPacketText, "bla bla bla\nbla bla\nbla\n"); - abortController.abort(); - conn.close(); - })(); - - return new Response(null, { status: 101 }); - }, { hostname: "localhost", port: listenPort, signal, keyFile, certFile }); - - await Promise.all([server, client()]); - }, -); - -Deno.test("upgradeHttp unix", { - permissions: { read: true, write: true }, - ignore: Deno.build.os === "windows", -}, async () => { - const filePath = tmpUnixSocketPath(); - const { promise, resolve } = Promise.withResolvers<void>(); - - async function client() { - const unixConn = await Deno.connect({ path: filePath, transport: "unix" }); - await unixConn.write( - new TextEncoder().encode( - "CONNECT server.example.com:80 HTTP/1.1\r\n\r\nbla bla bla\nbla bla\nbla\n", - ), - ); - setTimeout(async () => { - await unixConn.write( - new TextEncoder().encode( - "bla bla bla\nbla bla\nbla\n", - ), - ); - unixConn.close(); - resolve(); - }, 500); - await promise; - } - - const server = (async () => { - const listener = Deno.listen({ path: filePath, transport: "unix" }); - const conn = await listener.accept(); - listener.close(); - const httpConn = Deno.serveHttp(conn); - const reqEvent = await httpConn.nextRequest(); - assert(reqEvent); - const { request, respondWith } = reqEvent; - const p = Deno.upgradeHttp(request); - - const promise = (async () => { - const [conn, firstPacket] = await p; - const buf = new Uint8Array(1024); - const firstPacketText = new TextDecoder().decode(firstPacket); - assertEquals(firstPacketText, "bla bla bla\nbla bla\nbla\n"); - const n = await conn.read(buf); - assert(n != null); - const secondPacketText = new TextDecoder().decode(buf.slice(0, n)); - assertEquals(secondPacketText, "bla bla bla\nbla bla\nbla\n"); - conn.close(); - })(); - - const resp = new Response(null, { status: 101 }); - await respondWith(resp); - await promise; - httpConn!.close(); - })(); - - await Promise.all([server, client()]); -}); - Deno.test( { permissions: { net: true } }, async function httpServerReadLargeBodyWithContentLength() { |