diff options
author | ayame113 <40050810+ayame113@users.noreply.github.com> | 2022-10-05 15:51:59 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-05 12:21:59 +0530 |
commit | b5425ae2d37d3dd123cbc0430785c0f61082e3e3 (patch) | |
tree | 8f972ed187b82873587409b42fc06fe718b81b93 | |
parent | b312503f8f9d7b289b28c2235bdaba1259fc3c37 (diff) |
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.
-rw-r--r-- | cli/tests/unit/flash_test.ts | 27 | ||||
-rw-r--r-- | ext/flash/01_http.js | 3 |
2 files changed, 29 insertions, 1 deletions
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 @@ -1890,6 +1890,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() { const promise = deferred(); const ac = new AbortController(); diff --git a/ext/flash/01_http.js b/ext/flash/01_http.js index 789979ff9..17f99ca98 100644 --- a/ext/flash/01_http.js +++ b/ext/flash/01_http.js @@ -152,7 +152,8 @@ } // MUST NOT send Content-Length or Transfer-Encoding if status code is 1xx or 204. - if (status == 204 && status <= 100) { + if (status === 204 || status < 200) { + str += "\r\n"; return str; } |