From e57f0749e7129d0ee57f5b56dfed217ba0a52b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E6=9D=89?= Date: Fri, 1 May 2020 22:35:18 +0800 Subject: fix(std/http): avoid directly modifying the headers object (#5024) --- std/http/io_test.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'std/http/io_test.ts') 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 { const input = `GET / HTTP/1.1 malformedHeader -- cgit v1.2.3