-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
Description
I tried to create a simple HTTP server that uses endWithoutBody with a size argument to handle HEAD requests, but it crashes with the following error message:
Error: Returning from a request handler without responding or attaching an abort handler is forbidden!
terminate called without an active exception
Aborted
Code:
import uWebSockets from "uWebSockets.js";
const buffer = Buffer.from("Test", "utf-8");
const server = uWebSockets.App().any("/*", (res, req) => {
const path = req.getUrl();
const method = req.getCaseSensitiveMethod();
if (path === "/test") {
res.writeStatus("200")
.writeHeader("Content-Type", "text/plain")
.writeHeader("Content-Length", String(buffer.length));
if (method === "HEAD") {
res.endWithoutBody(buffer.length);
return;
}
res.end(buffer);
return;
}
res.writeStatus("404").writeHeader("Content-Type", "text/plain").end("404 Not Found");
}).listen("127.0.0.1", 8888, () => {
});When the res.endWithoutBody call is replaced with a res.end call with no arguments, this error does not occur. This behavior should be corrected because everything in the code is done synchronously, so there is no reason why the endWithoutBody behavior can't match the other, which sends a buffer and potentially requires more processing time.
If this is the intended behavior due to other considerations, it should at least be mentioned in the documentation or generate a warning message as the other functions do.