From 135319739943f4f036f77a70db2a96d4249bbd43 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sat, 16 Sep 2023 08:08:43 +0200 Subject: Override content-type for /feed-styles/ --- src/index.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index d4c7b3d..7a2c5f5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,6 +24,7 @@ type File = { handle: BunFile; relPath: string; headers?: Record; + type: string; size: number; mtime: Date; }; @@ -67,10 +68,12 @@ function registerFile( if (files.get(pathname) !== undefined) { console.warn("File already registered:", pathname); } + const handle = Bun.file(filename); files.set(pathname, { filename, relPath: "/" + path, - handle: Bun.file(filename), + handle: handle, + type: pathname.startsWith("/feed-styles") ? "text/xsl" : handle.type, headers: pathname === "/404.html" ? Object.assign({}, defaultHeaders, { "cache-control": "no-cache" }) @@ -185,7 +188,7 @@ const server = Bun.serve({ span.setTag("http.status_code", 200); return serveFile(files.get(file.relPath + ".br"), 200, { "content-encoding": "br", - "content-type": file.handle.type, + "content-type": file.type, }); } else if ( encodings.includes("zstd") && @@ -195,7 +198,7 @@ const server = Bun.serve({ span.setTag("http.status_code", 200); return serveFile(files.get(file.relPath + ".zst"), 200, { "content-encoding": "zstd", - "content-type": file.handle.type, + "content-type": file.type, }); } else if ( encodings.includes("gzip") && @@ -205,7 +208,7 @@ const server = Bun.serve({ span.setTag("http.status_code", 200); return serveFile(files.get(file.relPath + ".gz"), 200, { "content-encoding": "gzip", - "content-type": file.handle.type, + "content-type": file.type, }); } span.setTag("http.encoding", "identity"); -- cgit 1.4.1