summaryrefslogtreecommitdiff
path: root/cli/tests/unit/serve_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/unit/serve_test.ts')
-rw-r--r--cli/tests/unit/serve_test.ts42
1 files changed, 41 insertions, 1 deletions
diff --git a/cli/tests/unit/serve_test.ts b/cli/tests/unit/serve_test.ts
index 3f58903a8..76433f1e3 100644
--- a/cli/tests/unit/serve_test.ts
+++ b/cli/tests/unit/serve_test.ts
@@ -1,6 +1,9 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-import { assertMatch } from "../../../test_util/std/testing/asserts.ts";
+import {
+ assertMatch,
+ assertRejects,
+} from "../../../test_util/std/testing/asserts.ts";
import { Buffer, BufReader, BufWriter } from "../../../test_util/std/io/mod.ts";
import { TextProtoReader } from "../testdata/run/textproto.ts";
import {
@@ -879,6 +882,43 @@ Deno.test(
},
);
+Deno.test(
+ { permissions: { net: true } },
+ async function httpServerAbortedRequestBody() {
+ const promise = deferred();
+ const ac = new AbortController();
+ const listeningPromise = deferred();
+
+ const server = Deno.serve({
+ handler: async (request) => {
+ await assertRejects(async () => {
+ await request.text();
+ });
+ promise.resolve();
+ // Not actually used
+ return new Response();
+ },
+ port: servePort,
+ signal: ac.signal,
+ onListen: onListen(listeningPromise),
+ onError: createOnErrorCb(ac),
+ });
+
+ await listeningPromise;
+ const conn = await Deno.connect({ port: servePort });
+ // Send POST request with a body + content-length, but don't send it all
+ const encoder = new TextEncoder();
+ const body =
+ `POST / HTTP/1.1\r\nHost: 127.0.0.1:${servePort}\r\nContent-Length: 10\r\n\r\n12345`;
+ const writeResult = await conn.write(encoder.encode(body));
+ assertEquals(body.length, writeResult);
+ conn.close();
+ await promise;
+ ac.abort();
+ await server.finished;
+ },
+);
+
function createStreamTest(count: number, delay: number, action: string) {
function doAction(controller: ReadableStreamDefaultController, i: number) {
if (i == count) {