about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.ts51
1 files changed, 14 insertions, 37 deletions
diff --git a/src/app.ts b/src/app.ts
index 6843ccd..b2957aa 100644
--- a/src/app.ts
+++ b/src/app.ts
@@ -160,6 +160,8 @@ export const server = {
         });
       }
       const file = files.get(pathname);
+      let contentEncoding = "identity";
+      let suffix = "";
       if (file && (await file.handle.exists())) {
         if (
           parseIfModifiedSinceHeader(
@@ -178,50 +180,25 @@ export const server = {
           .split(",")
           .map((x) => x.trim().toLowerCase());
         if (encodings.includes("br") && files.has(pathname + ".br")) {
-          transaction.setHttpStatus(200);
-          metrics.requests.inc({
-            method: request.method,
-            path: pathname,
-            status_code: 200,
-            content_encoding: "br",
-          });
-          return serveFile(files.get(pathname + ".br"), 200, {
-            "content-encoding": "br",
-            "content-type": file.type,
-          });
+          contentEncoding = "br";
+          suffix = ".br";
         } else if (encodings.includes("zstd") && files.has(pathname + ".zst")) {
-          transaction.setHttpStatus(200);
-          metrics.requests.inc({
-            method: request.method,
-            path: pathname,
-            status_code: 200,
-            content_encoding: "zst",
-          });
-          return serveFile(files.get(pathname + ".zst"), 200, {
-            "content-encoding": "zstd",
-            "content-type": file.type,
-          });
+          contentEncoding = "zstd";
+          suffix = ".zst";
         } else if (encodings.includes("gzip") && files.has(pathname + ".gz")) {
-          transaction.setHttpStatus(200);
-          metrics.requests.inc({
-            method: request.method,
-            path: pathname,
-            status_code: 200,
-            content_encoding: "gzip",
-          });
-          return serveFile(files.get(pathname + ".gz"), 200, {
-            "content-encoding": "gzip",
-            "content-type": file.type,
-          });
+          contentEncoding = "gzip";
+          suffix = ".gz";
         }
-        transaction.setHttpStatus(200);
+        const status = 200;
+        transaction.setHttpStatus(status);
         metrics.requests.inc({
           method: request.method,
           path: pathname,
-          status_code: 200,
-          content_encoding: "identity",
+          status_code: status,
+          content_encoding: contentEncoding,
         });
-        return serveFile(file, 200, {
+        return serveFile(files.get(pathname + suffix), status, {
+          "content-encoding": contentEncoding,
           "content-type": file.type,
         });
       } else {