Add Cookie header parse + Set-Cookie build helpers (todo §0); destroy response on static mid-stream error

This commit is contained in:
2026-06-14 18:41:31 +02:00
parent 5020be592a
commit b4c149db27
4 changed files with 215 additions and 2 deletions

View File

@@ -48,7 +48,11 @@ export async function serveStatic(dir: string, requestedPath: string, res: Serve
const info = await stat(filePath);
if (!info.isFile()) return plain(res, 404, "Not Found");
res.writeHead(200, { "content-length": info.size, "content-type": contentTypeFor(filePath) });
createReadStream(filePath).pipe(res);
// Headers are already sent, so a mid-stream read error can't become an HTTP error —
// destroy the response to signal a truncated body instead of leaving the socket open.
createReadStream(filePath)
.on("error", () => res.destroy())
.pipe(res);
} catch {
plain(res, 404, "Not Found");
}