Files
scriptc/tests/corpus/2977-http-static-incoming-timeout.ts
Chris Tate d8f6d7cf94 Fix static string position defaults and coercion (#416)
* Fix static string position defaults and coercion

* Stabilize HTTP timeout differential fixtures
2026-09-25 00:42:37 -05:00

30 lines
793 B
TypeScript

import { createServer, get } from "node:http";
let sendLate = () => {};
const server = createServer((_request, response) => {
let sent = false;
const finish = () => {
if (sent) return;
sent = true;
response.end("late");
};
const fallback = setTimeout(finish, 2000);
sendLate = () => { clearTimeout(fallback); finish(); };
response.flushHeaders();
});
server.listen(0, () => {
get({ port: server.address().port }, (response) => {
response.setTimeout(15, () => {
console.log("timed out", response.complete);
sendLate();
});
let body = "";
response.on("data", (chunk: Buffer) => { body += chunk.toString("utf8"); });
response.on("end", () => {
console.log("body", body, response.complete);
server.close();
});
});
});