@@ -15,7 +15,33 @@ import {
1515import type { Precondition } from "../types.ts" ;
1616import { ifMatch } from "./utils.ts" ;
1717
18- /** `If-Match` header field precondition. */
18+ /** `If-Match` header field precondition.
19+ *
20+ * @example
21+ * ```ts
22+ * import { IfMatch } from "https://deno.land/x/conditional_request_middleware@$VERSION/mod.ts";
23+ * import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
24+ *
25+ * const precondition = new IfMatch();
26+ * const request = new Request("<uri>", {
27+ * headers: { "if-match": "<strong:etag>" },
28+ * });
29+ * const selectedRepresentation = new Response("<content>", {
30+ * headers: { etag: "<weak:etag>" },
31+ * });
32+ * declare const evalResult: false;
33+ *
34+ * assertEquals(precondition.field, "if-match");
35+ * assertEquals(
36+ * precondition.evaluate(request, selectedRepresentation),
37+ * evalResult,
38+ * );
39+ * assertEquals(
40+ * precondition.respond(request, selectedRepresentation, evalResult)?.status,
41+ * 412,
42+ * );
43+ * ```
44+ */
1945export class IfMatch implements Precondition {
2046 field = ConditionalHeader . IfMatch ;
2147
@@ -36,7 +62,7 @@ export class IfMatch implements Precondition {
3662 _ : unknown ,
3763 response : Response ,
3864 result : boolean ,
39- ) : undefined | Response {
65+ ) : Response | undefined {
4066 if ( result ) return ;
4167
4268 const headers = filterKeys ( response . headers , not ( isRepresentationHeader ) ) ;
0 commit comments