8000 fix: 🐛 Deliver etags also for home route by dkolba · Pull Request #5 · dkolba/luhmann · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,10 @@ export async function pathHandler({
mediaBaseUrl: resource,
});
const body = template(markup?.toString(), stylesheetlinks, css);
const etag = await calculate(body);

const headers = new Headers({
"content-type": "text/html",
});
etag && headers.append("etag", etag);
return { body, headers, status: 200 };
}

Expand All @@ -301,13 +299,17 @@ async function reply(
},
) {
const bodyEtag = await calculate(body);
console.log("bodyEtag : ", bodyEtag);
console.log("ifNoneMatch: ", ifNoneMatch);
if (`W/${bodyEtag}` === ifNoneMatch) {
return new Response(null, {
headers: headers,
status: 304,
});
}

const etag = await calculate(body);
etag && headers.append("etag", etag);
return new Response(body, {
headers: headers,
status,
Expand Down
0