mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
Co-authored-by: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Co-authored-by: 190n <ben@bun.sh> Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
33 lines
938 B
JavaScript
33 lines
938 B
JavaScript
import http from "node:http";
|
|
import assert from "node:assert";
|
|
import { once } from "node:events";
|
|
import { connect } from "node:net";
|
|
|
|
const { promise: uncaughtExceptionPromise, resolve, reject } = Promise.withResolvers();
|
|
|
|
process.once("uncaughtException", err => {
|
|
resolve(err);
|
|
});
|
|
|
|
await using server = http.createServer(reject);
|
|
|
|
server.on("clientError", () => {
|
|
throw new Error("thrown from clientError");
|
|
});
|
|
|
|
server.listen(0);
|
|
await once(server, "listening");
|
|
|
|
const port = server.address().port;
|
|
const client = connect(port, undefined, () => {
|
|
// HTTP request with invalid Content-Length
|
|
// The Content-Length says 10 but the actual body is 20 bytes
|
|
// Send the request
|
|
client.write(
|
|
`POST /test HTTP/1.1\r\nHost: localhost:${port}\r\nContent-Type: text/plain\r\nContent-Length: invalid\r\n\r\n`,
|
|
);
|
|
});
|
|
|
|
const err = await uncaughtExceptionPromise;
|
|
assert.strictEqual(err.message, "thrown from clientError");
|