diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-04-24 23:24:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-24 23:24:40 +0200 |
commit | bb74e75a049768c2949aa08de6752a16813b97de (patch) | |
tree | 0c6af6d5ef1b8e8aff878d9e2aa8c32bee1c4c39 /cli/tests/unit/serve_test.ts | |
parent | 0e97fa4d5f056e12d3c0704bfb7bcdc56316ef94 (diff) |
feat(ext/http): h2c for http/2 (#18817)
This implements HTTP/2 prior-knowledge connections, allowing clients to
request HTTP/2 over plaintext or TLS-without-ALPN connections. If a
client requests a specific protocol via ALPN (`h2` or `http/1.1`),
however, the protocol is forced and must be used.
Diffstat (limited to 'cli/tests/unit/serve_test.ts')
-rw-r--r-- | cli/tests/unit/serve_test.ts | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/cli/tests/unit/serve_test.ts b/cli/tests/unit/serve_test.ts index 9268c7aab..55b7c4590 100644 --- a/cli/tests/unit/serve_test.ts +++ b/cli/tests/unit/serve_test.ts @@ -15,6 +15,7 @@ import { deferred, fail, } from "./test_util.ts"; +import { consoleSize } from "../../../runtime/js/40_tty.js"; function createOnErrorCb(ac: AbortController): (err: unknown) => Response { return (err) => { @@ -2709,3 +2710,80 @@ function isProhibitedForTrailer(key: string): boolean { const s = new Set(["transfer-encoding", "content-length", "trailer"]); return s.has(key.toLowerCase()); } + +Deno.test( + { permissions: { net: true, run: true } }, + async function httpServeCurlH2C() { + const ac = new AbortController(); + const server = Deno.serve( + () => new Response("hello world!"), + { signal: ac.signal }, + ); + + assertEquals( + "hello world!", + await curlRequest(["http://localhost:8000/path"]), + ); + assertEquals( + "hello world!", + await curlRequest(["http://localhost:8000/path", "--http2"]), + ); + assertEquals( + "hello world!", + await curlRequest([ + "http://localhost:8000/path", + "--http2", + "--http2-prior-knowledge", + ]), + ); + + ac.abort(); + await server; + }, +); + +Deno.test( + { permissions: { net: true, run: true, read: true } }, + async function httpsServeCurlH2C() { + const ac = new AbortController(); + const server = Deno.serve( + () => new Response("hello world!"), + { + signal: ac.signal, + cert: Deno.readTextFileSync("cli/tests/testdata/tls/localhost.crt"), + key: Deno.readTextFileSync("cli/tests/testdata/tls/localhost.key"), + }, + ); + + assertEquals( + "hello world!", + await curlRequest(["https://localhost:9000/path", "-k"]), + ); + assertEquals( + "hello world!", + await curlRequest(["https://localhost:9000/path", "-k", "--http2"]), + ); + assertEquals( + "hello world!", + await curlRequest([ + "https://localhost:9000/path", + "-k", + "--http2", + "--http2-prior-knowledge", + ]), + ); + + ac.abort(); + await server; + }, +); + +async function curlRequest(args: string[]) { + const { success, stdout } = await new Deno.Command("curl", { + args, + stdout: "piped", + stderr: "null", + }).output(); + assert(success); + return new TextDecoder().decode(stdout); +} |