summaryrefslogtreecommitdiff
path: root/std/http/io_test.ts
diff options
context:
space:
mode:
author木杉 <zhmushan@qq.com>2020-05-01 22:35:18 +0800
committerGitHub <noreply@github.com>2020-05-01 10:35:18 -0400
commite57f0749e7129d0ee57f5b56dfed217ba0a52b94 (patch)
treef4d802219c9e43266f7df75f9c51e5f5c483bbf8 /std/http/io_test.ts
parentbe65f6692f0f81dc88c77ba4cf22cdda40760317 (diff)
fix(std/http): avoid directly modifying the headers object (#5024)
Diffstat (limited to 'std/http/io_test.ts')
-rw-r--r--std/http/io_test.ts13
1 files changed, 12 insertions, 1 deletions
diff --git a/std/http/io_test.ts b/std/http/io_test.ts
index fd41b474e..c0f57a1b7 100644
--- a/std/http/io_test.ts
+++ b/std/http/io_test.ts
@@ -19,7 +19,7 @@ import { chunkedBodyReader } from "./io.ts";
import { ServerRequest, Response } from "./server.ts";
import { StringReader } from "../io/readers.ts";
import { mockConn } from "./mock.ts";
-const { Buffer, test } = Deno;
+const { Buffer, test, readAll } = Deno;
test("bodyReader", async () => {
const text = "Hello, Deno";
@@ -357,6 +357,17 @@ test("writeResponse with trailer", async () => {
assertEquals(ret, exp);
});
+test("writeResponseShouldNotModifyOriginHeaders", async () => {
+ const headers = new Headers();
+ const buf = new Deno.Buffer();
+
+ await writeResponse(buf, { body: "foo", headers });
+ assert(decode(await readAll(buf)).includes("content-length: 3"));
+
+ await writeResponse(buf, { body: "hello", headers });
+ assert(decode(await readAll(buf)).includes("content-length: 5"));
+});
+
test("readRequestError", async function (): Promise<void> {
const input = `GET / HTTP/1.1
malformedHeader