Invoking `endWithoutBody` with a size, without invoking `onAborted` is forbidden
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.
Strange. Does it happen if you just make the most minimal app.get -> res.endWithoutBody() ?
Okay yes it does. I get it. It only happens if you pass a number. Makes sense.
https://github.com/uNetworking/uWebSockets/commit/c8da12b537516489b2e01dacf4d836b5bc74e826
This fixes it. I need to make a new release but it will take some time. Haven't done one in a while.