From 7c64360212a54cf259c503929c74c6c92c4d875d Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Wed, 13 Sep 2023 06:04:08 +0200 Subject: Reduce memory usage by not duplicating default headers --- src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index 030b0bd..418af5c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,7 +19,7 @@ function getFilename(name: string): string { type File = { filename: string; - headers: Record; + headers?: Record; size: number; mtime: string; }; @@ -37,7 +37,7 @@ function registerFile(pathname: string, filename: string, stat: Stats): void { headers: pathname === "/404.html" ? Object.assign({}, defaultHeaders, { "cache-control": "no-cache" }) - : defaultHeaders, + : undefined, size: stat.size, mtime: stat.mtime.toUTCString(), }); @@ -72,7 +72,7 @@ async function serveFile( ): Promise { if (file && (await fsp.exists(file.filename))) { return new Response(Bun.file(file.filename), { - headers: file.headers, + headers: file.headers || defaultHeaders, status: statusCode, }); } else { -- cgit 1.4.1