From b5425ae2d37d3dd123cbc0430785c0f61082e3e3 Mon Sep 17 00:00:00 2001 From: ayame113 <40050810+ayame113@users.noreply.github.com> Date: Wed, 5 Oct 2022 15:51:59 +0900 Subject: fix(ext/flash): Avoid sending Content-Length when status code is 204 (#15901) Currently Content-Length is sent when the status code is 204. However, according to the spec, this should not be sent. Modify the if statement below to prevent the Content-Length from being sent. --- cli/tests/unit/flash_test.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'cli/tests') diff --git a/cli/tests/unit/flash_test.ts b/cli/tests/unit/flash_test.ts index 48310296e..a5a31a136 100644 --- a/cli/tests/unit/flash_test.ts +++ b/cli/tests/unit/flash_test.ts @@ -1888,6 +1888,33 @@ Deno.test( }, ); +Deno.test( + { permissions: { net: true } }, + async function httpServer204ResponseDoesntSendContentLength() { + const listeningPromise = deferred(); + const ac = new AbortController(); + const server = Deno.serve({ + handler: (_request) => new Response(null, { status: 204 }), + port: 4501, + signal: ac.signal, + onListen: onListen(listeningPromise), + onError: createOnErrorCb(ac), + }); + + try { + await listeningPromise; + const resp = await fetch("http://127.0.0.1:4501/", { + method: "GET", + headers: { "connection": "close" }, + }); + assertEquals(resp.headers.get("Content-Length"), null); + } finally { + ac.abort(); + await server; + } + }, +); + Deno.test( { permissions: { net: true } }, async function httpServer304ResponseDoesntSendBody() { -- cgit v1.2.3