Don't overwrite what net.fetch already added

This commit is contained in:
Manav Rathi 2024-04-26 16:06:45 +05:30
parent faba29b422
commit 21ad409c61
No known key found for this signature in database

View file

@ -57,10 +57,12 @@ const handleRead = async (path: string) => {
try {
const res = await net.fetch(pathToFileURL(path).toString());
if (res.ok) {
// net.fetch defaults to text/plain, which might be fine
// in practice, but as an extra precaution indicate that
// this is binary data.
res.headers.set("Content-Type", "application/octet-stream");
// `net.fetch` already seems to add "Content-Type" and
// "Last-Modified" headers. But since we already are stat-ting the
// file for the "Content-Length", we explicitly add the
// "X-Last-Modified-Ms" too, (a) guaranteeing its presence, and (b)
// having it be in the exact format we want (no string <-> date
// conversions) and (c) keeping milliseconds.
const stat = await fs.stat(path);