Merge branch 'main' into kai/http-chunks

This commit is contained in:
Kai Tamkun
2025-04-17 14:49:16 -07:00
602 changed files with 7621 additions and 6059 deletions

View File

@@ -2371,3 +2371,49 @@ it("Empty requests should not be Transfer-Encoding: chunked", async () => {
server.close();
}
});
it("should reject non-standard body writes when rejectNonStandardBodyWrites is true", async () => {
{
let body_not_allowed_on_write;
let body_not_allowed_on_end;
for (const rejectNonStandardBodyWrites of [true, false, undefined]) {
await using server = http.createServer({
rejectNonStandardBodyWrites,
});
server.on("request", (req, res) => {
body_not_allowed_on_write = false;
body_not_allowed_on_end = false;
res.writeHead(204);
try {
res.write("bun");
} catch (e: any) {
expect(e?.code).toBe("ERR_HTTP_BODY_NOT_ALLOWED");
body_not_allowed_on_write = true;
}
try {
res.end("bun");
} catch (e: any) {
expect(e?.code).toBe("ERR_HTTP_BODY_NOT_ALLOWED");
body_not_allowed_on_end = true;
// if we throw here, we need to call end() to actually end the request
res.end();
}
});
await once(server.listen(0), "listening");
const url = `http://localhost:${server.address().port}`;
{
await fetch(url, {
method: "GET",
}).then(res => res.text());
expect(body_not_allowed_on_write).toBe(rejectNonStandardBodyWrites || false);
expect(body_not_allowed_on_end).toBe(rejectNonStandardBodyWrites || false);
}
}
}
});