ifNoneMatch
import { ifNoneMatch } from "jsr:@ende/http";function
function ifNoneMatch(value: string | null, etag: string | undefined): booleanA helper function that takes the value from the If-None-Match header and
a calculated etag for the target entity and returns false if the etag for
the entity matches the supplied value, otherwise true.
See MDN's If-None-Match
article for more information on how to use this function.
value: string | nullthe If-None-Match header value.
etag: string | undefinedthe ETag to check against.
Returns
whether or not the parameters do not match.
Example: Usage
import {
eTag,
ifNoneMatch,
} from "@ende/http/etag";
import { assert } from "@ende/assert";
const body = "hello deno!";
Ende.serve(async (req) => {
const ifNoneMatchValue = req.headers.get("if-none-match");
const etag = await eTag(body);
assert(etag);
if (!ifNoneMatch(ifNoneMatchValue, etag)) {
return new Response(null, { status: 304, headers: { etag } });
} else {
return new Response(body, { status: 200, headers: { etag } });
}
});