dsh-vscode-mode 0.1.25 → 0.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
- import { readFile } from "node:fs/promises";
2
+ import { readFile, stat } from "node:fs/promises";
3
3
  import { dirname, extname, join, normalize, resolve, sep } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { existsSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
@@ -613,10 +613,28 @@ function registerRoutes(ctx, config, handleRpc, onWarning) {
613
613
  res.end();
614
614
  return;
615
615
  }
616
+ const info = await stat(target).catch(() => null);
617
+ if (!info || !info.isFile()) {
618
+ res.statusCode = 404;
619
+ res.end();
620
+ return;
621
+ }
622
+ const etag = "W/\"" + info.mtimeMs.toString(16) + "-" + info.size.toString(16) + "\"";
623
+ if ((() => {
624
+ const raw = req.headers?.["if-none-match"];
625
+ if (Array.isArray(raw)) return raw[0];
626
+ return raw;
627
+ })() === etag) {
628
+ res.statusCode = 304;
629
+ res.setHeader("etag", etag);
630
+ res.end();
631
+ return;
632
+ }
616
633
  const body = await readFile(target);
617
634
  res.statusCode = 200;
618
635
  res.setHeader("content-type", VENDOR_MIME[extname(target)] ?? "application/octet-stream");
619
636
  res.setHeader("cache-control", "public, max-age=3600");
637
+ res.setHeader("etag", etag);
620
638
  res.end(body);
621
639
  } catch (error) {
622
640
  res.statusCode = 404;