From 3fca211a5e26a594fab44b3d84437ebaecc0124a Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sun, 24 Sep 2023 07:18:15 +0200 Subject: Fix serving pre-compressed files --- src/app.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/app.ts b/src/app.ts index 57ae71d..e03f50e 100644 --- a/src/app.ts +++ b/src/app.ts @@ -165,30 +165,24 @@ export const server = { const encodings = (request.headers.get("accept-encoding") || "") .split(",") .map((x) => x.trim().toLowerCase()); - if (encodings.includes("br") && files.has(file.relPath + ".br")) { + if (encodings.includes("br") && files.has(pathname + ".br")) { transaction.setHttpStatus(200); transaction.setTag("http.content-encoding", "br"); - return serveFile(files.get(file.relPath + ".br"), 200, { + return serveFile(files.get(pathname + ".br"), 200, { "content-encoding": "br", "content-type": file.type, }); - } else if ( - encodings.includes("zstd") && - files.has(file.relPath + ".zst") - ) { + } else if (encodings.includes("zstd") && files.has(pathname + ".zst")) { transaction.setHttpStatus(200); transaction.setTag("http.content-encoding", "zstd"); - return serveFile(files.get(file.relPath + ".zst"), 200, { + return serveFile(files.get(pathname + ".zst"), 200, { "content-encoding": "zstd", "content-type": file.type, }); - } else if ( - encodings.includes("gzip") && - files.has(file.relPath + ".gz") - ) { + } else if (encodings.includes("gzip") && files.has(pathname + ".gz")) { transaction.setHttpStatus(200); transaction.setTag("http.content-encoding", "gzip"); - return serveFile(files.get(file.relPath + ".gz"), 200, { + return serveFile(files.get(pathname + ".gz"), 200, { "content-encoding": "gzip", "content-type": file.type, }); -- cgit 1.4.1