mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
const { AsyncLocalStorage } = require("async_hooks");
|
|
const http = require("http");
|
|
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
let failed = false;
|
|
|
|
const server = http.createServer((req, res) => {
|
|
res.end("ok");
|
|
});
|
|
|
|
server.listen(0, () => {
|
|
const port = server.address().port;
|
|
|
|
asyncLocalStorage.run({ test: "http.request" }, () => {
|
|
const req = http.request(
|
|
{
|
|
port,
|
|
method: "GET",
|
|
},
|
|
res => {
|
|
if (asyncLocalStorage.getStore()?.test !== "http.request") {
|
|
console.error("FAIL: http.request response callback lost context");
|
|
failed = true;
|
|
}
|
|
|
|
res.on("data", chunk => {
|
|
if (asyncLocalStorage.getStore()?.test !== "http.request") {
|
|
console.error("FAIL: http response data event lost context");
|
|
failed = true;
|
|
}
|
|
});
|
|
|
|
res.on("end", () => {
|
|
if (asyncLocalStorage.getStore()?.test !== "http.request") {
|
|
console.error("FAIL: http response end event lost context");
|
|
failed = true;
|
|
}
|
|
server.close();
|
|
process.exit(failed ? 1 : 0);
|
|
});
|
|
},
|
|
);
|
|
|
|
req.on("error", () => {
|
|
server.close();
|
|
process.exit(1);
|
|
});
|
|
|
|
req.end();
|
|
});
|
|
});
|