mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 20:39:05 +00:00
Merge branch 'main' into kai/http-chunks
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user