summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/tests/unit/serve_test.ts50
1 files changed, 50 insertions, 0 deletions
diff --git a/cli/tests/unit/serve_test.ts b/cli/tests/unit/serve_test.ts
index c6cfc45f3..0f97e17b8 100644
--- a/cli/tests/unit/serve_test.ts
+++ b/cli/tests/unit/serve_test.ts
@@ -15,6 +15,7 @@ import {
const {
upgradeHttpRaw,
+ addTrailers,
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol
} = Deno[Deno.internal];
@@ -2903,6 +2904,45 @@ Deno.test(
},
);
+// TODO(mmastrac): This test should eventually use fetch, when we support trailers there.
+// This test is ignored because it's flaky and relies on cURL's verbose output.
+Deno.test(
+ { permissions: { net: true, run: true, read: true }, ignore: true },
+ async function httpServerTrailers() {
+ const ac = new AbortController();
+ const listeningPromise = deferred();
+
+ const server = Deno.serve({
+ handler: () => {
+ const response = new Response("Hello World", {
+ headers: {
+ "trailer": "baz",
+ "transfer-encoding": "chunked",
+ "foo": "bar",
+ },
+ });
+ addTrailers(response, [["baz", "why"]]);
+ return response;
+ },
+ port: 4501,
+ signal: ac.signal,
+ onListen: onListen(listeningPromise),
+ onError: createOnErrorCb(ac),
+ });
+
+ // We don't have a great way to access this right now, so just fetch the trailers with cURL
+ const [_, stderr] = await curlRequestWithStdErr([
+ "http://localhost:4501/path",
+ "-v",
+ "--http2",
+ "--http2-prior-knowledge",
+ ]);
+ assertMatch(stderr, /baz: why/);
+ ac.abort();
+ await server;
+ },
+);
+
Deno.test(
{ permissions: { net: true, run: true, read: true } },
async function httpsServeCurlH2C() {
@@ -2948,3 +2988,13 @@ async function curlRequest(args: string[]) {
assert(success);
return new TextDecoder().decode(stdout);
}
+
+async function curlRequestWithStdErr(args: string[]) {
+ const { success, stdout, stderr } = await new Deno.Command("curl", {
+ args,
+ stdout: "piped",
+ stderr: "piped",
+ }).output();
+ assert(success);
+ return [new TextDecoder().decode(stdout), new TextDecoder().decode(stderr)];
+}