mirror of
https://github.com/denoland/deno.git
synced 2025-02-08 07:16:56 -05:00
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.
This commit is contained in:
parent
b312503f8f
commit
b5425ae2d3
2 changed files with 29 additions and 1 deletions
|
@ -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(
|
Deno.test(
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
async function httpServer304ResponseDoesntSendBody() {
|
async function httpServer304ResponseDoesntSendBody() {
|
||||||
|
|
|
@ -152,7 +152,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// MUST NOT send Content-Length or Transfer-Encoding if status code is 1xx or 204.
|
// 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;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue