Function ifNoneMatch
- if
None (value, etag): booleanMatch Parameters
- value: null | string
the If-None-Match header value.
- etag: undefined | string
the ETag to check against.
Returns boolean
whether or not the parameters do not match.
Example: Usage
import {
eTag,
ifNoneMatch,
} from "@std/http/etag";
import { assert } from "@std/assert";
const body = "hello deno!";
Deno.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 } });
}
});- value: null | string
A helper function that takes the value from the
If-None-Matchheader and a calculated etag for the target entity and returnsfalseif the etag for the entity matches the supplied value, otherwisetrue.See MDN's
If-None-Matcharticle for more information on how to use this function.