fix: improved etag handling in static files (#198)

This commit is contained in:
Luca Casonato
2022-05-19 19:05:07 +02:00
committed by GitHub
parent 2a2b948a58
commit c1a9d53b18
2 changed files with 42 additions and 19 deletions
+20 -2
View File
@@ -187,16 +187,34 @@ Deno.test("static file - by file path", async () => {
assertEquals(resp.status, 200);
const body = await resp.text();
assert(body.startsWith("bar"));
assert(resp.headers.get("etag"));
const etag = resp.headers.get("etag");
assert(etag);
// The etag is not weak, because this did not go through content encoding, so
// this is not a real server.
assert(!etag.startsWith("W/"), "etag should be weak");
assertEquals(resp.headers.get("content-type"), "text/plain");
const resp2 = await router(
new Request("https://fresh.deno.dev/foo.txt", {
headers: {
"if-none-match": resp.headers.get("etag")!,
"if-none-match": etag,
},
}),
);
assertEquals(resp2.status, 304);
assertEquals(resp2.headers.get("etag"), etag);
assertEquals(resp2.headers.get("content-type"), "text/plain");
const resp3 = await router(
new Request("https://fresh.deno.dev/foo.txt", {
headers: {
"if-none-match": `W/${etag}`,
},
}),
);
assertEquals(resp3.status, 304);
assertEquals(resp3.headers.get("etag"), etag);
assertEquals(resp3.headers.get("content-type"), "text/plain");
});
Deno.test("static file - by 'hashed' path", async () => {