From e39dace8cb4b1868e811fd13b87f2a81e84b98ce Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Mon, 25 Oct 2021 09:41:06 -0700 Subject: fix(tls): Make TLS clients support HTTP/2 (#12530) `fetch()` and client-side websocket used to support HTTP/2, but this regressed in #11491. This patch reenables it by explicitly adding `h2` and `http/1.1` to the list of ALPN protocols on the HTTP and websocket clients. --- cli/tests/unit/fetch_test.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'cli/tests/unit/fetch_test.ts') diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index a2bd1741b..bc61d67b5 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -1324,3 +1324,39 @@ unitTest( }), TypeError); }, ); + +unitTest( + { permissions: { net: true, read: true } }, + async function fetchSupportsHttp1Only() { + const caCert = await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem"); + const client = Deno.createHttpClient({ caCerts: [caCert] }); + const res = await fetch("https://localhost:5546/http_version", { client }); + assert(res.ok); + assertEquals(await res.text(), "HTTP/1.1"); + client.close(); + }, +); + +unitTest( + { permissions: { net: true, read: true } }, + async function fetchSupportsHttp2() { + const caCert = await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem"); + const client = Deno.createHttpClient({ caCerts: [caCert] }); + const res = await fetch("https://localhost:5547/http_version", { client }); + assert(res.ok); + assertEquals(await res.text(), "HTTP/2.0"); + client.close(); + }, +); + +unitTest( + { permissions: { net: true, read: true } }, + async function fetchPrefersHttp2() { + const caCert = await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem"); + const client = Deno.createHttpClient({ caCerts: [caCert] }); + const res = await fetch("https://localhost:5545/http_version", { client }); + assert(res.ok); + assertEquals(await res.text(), "HTTP/2.0"); + client.close(); + }, +); -- cgit v1.2.3