Function ifMatch
- if
Match (value, etag): boolean Parameters
- value: null | string
the If-Match header value.
- etag: undefined | string
the ETag to check against.
Returns boolean
whether or not the parameters match.
Example: Usage
import {
eTag,
ifMatch,
} from "@std/http/etag";
import { assert } from "@std/assert";
const body = "hello deno!";
Deno.serve(async (req) => {
const ifMatchValue = req.headers.get("if-match");
const etag = await eTag(body);
assert(etag);
if (!ifMatchValue || ifMatch(ifMatchValue, etag)) {
return new Response(body, { status: 200, headers: { etag } });
} else {
return new Response(null, { status: 412, statusText: "Precondition Failed"});
}
});- value: null | string
A helper function that takes the value from the
If-Matchheader and a calculated etag for the target. By using strong comparison, returntrueif the values match, otherwisefalse.See MDN's
If-Matcharticle for more information on how to use this function.