summaryrefslogtreecommitdiff
path: root/cli/tests/unit/http_test.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2021-08-16 13:43:43 +0200
committerGitHub <noreply@github.com>2021-08-16 13:43:43 +0200
commitd1d2388d7f1a09fd2469b356f00b6b361269a0b7 (patch)
tree31c9939eb8376e1c881d7a3d303cdd80284773e5 /cli/tests/unit/http_test.ts
parent163f2ef57117afd410f03be7e7519fc89bd18173 (diff)
test(ext/http): add test for incomplete HTTP message and fix resource leak (#11717)
This commit adds a test case for "Http: connection closed before message completed" error as well as fixing an edge with resource leak when the error is raised.
Diffstat (limited to 'cli/tests/unit/http_test.ts')
-rw-r--r--cli/tests/unit/http_test.ts64
1 files changed, 64 insertions, 0 deletions
diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts
index 5262c5919..f8de63383 100644
--- a/cli/tests/unit/http_test.ts
+++ b/cli/tests/unit/http_test.ts
@@ -751,3 +751,67 @@ unitTest({ perms: { net: true } }, async function httpServerPanic() {
client.close();
listener.close();
});
+
+// https://github.com/denoland/deno/issues/11595
+unitTest(
+ { perms: { net: true } },
+ async function httpServerIncompleteMessage() {
+ const listener = Deno.listen({ port: 4501 });
+ const def1 = deferred();
+ const def2 = deferred();
+
+ const client = await Deno.connect({ port: 4501 });
+ await client.write(new TextEncoder().encode(
+ `GET / HTTP/1.0\r\n\r\n`,
+ ));
+
+ const conn = await listener.accept();
+ const httpConn = Deno.serveHttp(conn);
+ const ev = await httpConn.nextRequest();
+ const { respondWith } = ev!;
+
+ const { readable, writable } = new TransformStream<Uint8Array>();
+ const writer = writable.getWriter();
+
+ async function writeResponse() {
+ await writer.write(
+ new TextEncoder().encode(
+ "written to the writable side of a TransformStream",
+ ),
+ );
+ await writer.close();
+ }
+
+ const errors: Error[] = [];
+
+ writeResponse()
+ .catch((error: Error) => {
+ errors.push(error);
+ })
+ .then(() => def1.resolve());
+
+ const res = new Response(readable);
+
+ respondWith(res)
+ .catch((error: Error) => errors.push(error))
+ .then(() => def2.resolve());
+
+ client.close();
+
+ await Promise.all([
+ def1,
+ def2,
+ ]);
+
+ listener.close();
+
+ assertEquals(errors.length, 2);
+ for (const error of errors) {
+ assertEquals(error.name, "Http");
+ assertEquals(
+ error.message,
+ "connection closed before message completed",
+ );
+ }
+ },
+);