about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorAlan Pearce2023-09-13 06:04:08 +0200
committerAlan Pearce2023-09-13 06:19:04 +0200
commit7c64360212a54cf259c503929c74c6c92c4d875d (patch)
tree2470bd05437f69d33778cd9c0ebc8df2a01e780e /src
parentb89c78af528b400d31ce59576fc4238b902a9cfe (diff)
downloadwebsite-7c64360212a54cf259c503929c74c6c92c4d875d.tar.lz
website-7c64360212a54cf259c503929c74c6c92c4d875d.tar.zst
website-7c64360212a54cf259c503929c74c6c92c4d875d.zip
Reduce memory usage by not duplicating default headers
Diffstat (limited to 'src')
-rw-r--r--src/index.ts6
1 files changed, 3 insertions, 3 deletions
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<string, string>;
+  headers?: Record<string, string>;
   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<Response> {
   if (file && (await fsp.exists(file.filename))) {
     return new Response(Bun.file(file.filename), {
-      headers: file.headers,
+      headers: file.headers || defaultHeaders,
       status: statusCode,
     });
   } else {