summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/http_test.ts62
1 files changed, 62 insertions, 0 deletions
diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts
index 779f11e56..9afe22553 100644
--- a/cli/tests/unit/http_test.ts
+++ b/cli/tests/unit/http_test.ts
@@ -73,6 +73,68 @@ Deno.test({ permissions: { net: true } }, async function httpServerBasic() {
await promise;
});
+// https://github.com/denoland/deno/issues/15107
+Deno.test(
+ { permissions: { net: true } },
+ async function httpLazyHeadersIssue15107() {
+ let headers: Headers;
+ const promise = (async () => {
+ const listener = Deno.listen({ port: 2333 });
+ const conn = await listener.accept();
+ listener.close();
+ const httpConn = Deno.serveHttp(conn);
+ const e = await httpConn.nextRequest();
+ assert(e);
+ const { request } = e;
+ request.text();
+ headers = request.headers;
+ httpConn.close();
+ })();
+
+ const conn = await Deno.connect({ port: 2333 });
+ // Send GET request with a body + content-length.
+ const encoder = new TextEncoder();
+ const body =
+ `GET / HTTP/1.1\r\nHost: 127.0.0.1:2333\r\nContent-Length: 5\r\n\r\n12345`;
+ const writeResult = await conn.write(encoder.encode(body));
+ assertEquals(body.length, writeResult);
+ await promise;
+ conn.close();
+ assertEquals(headers!.get("content-length"), "5");
+ },
+);
+
+Deno.test(
+ { permissions: { net: true } },
+ async function httpReadHeadersAfterClose() {
+ const promise = (async () => {
+ const listener = Deno.listen({ port: 2334 });
+ const conn = await listener.accept();
+ listener.close();
+ const httpConn = Deno.serveHttp(conn);
+ const e = await httpConn.nextRequest();
+ assert(e);
+ const { request, respondWith } = e;
+
+ await request.text(); // Read body
+ await respondWith(new Response("Hello World")); // Closes request
+
+ assertThrows(() => request.headers, TypeError, "request closed");
+ httpConn.close();
+ })();
+
+ const conn = await Deno.connect({ port: 2334 });
+ // Send GET request with a body + content-length.
+ const encoder = new TextEncoder();
+ const body =
+ `GET / HTTP/1.1\r\nHost: 127.0.0.1:2333\r\nContent-Length: 5\r\n\r\n12345`;
+ const writeResult = await conn.write(encoder.encode(body));
+ assertEquals(body.length, writeResult);
+ await promise;
+ conn.close();
+ },
+);
+
Deno.test(
{ permissions: { net: true } },
async function httpServerGetRequestBody() {