Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/capi/deps/std/http.ts>ifNoneMatch

[WIP] A framework for crafting interactions with Substrate chains
Latest
function ifNoneMatch
import { ifNoneMatch } from "https://deno.land/x/capi@v0.1.1-beta.1/deps/std/http.ts";

A 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.

import {
  calculate,
  ifNoneMatch,
} from "https://deno.land/std@0.224.0/http/etag.ts";
import { serve } from "https://deno.land/std@0.224.0/http/server.ts";
import { assert } from "https://deno.land/std@0.224.0/testing/asserts.ts"

const body = "hello deno!";

await serve(async (req) => {
  const ifNoneMatchValue = req.headers.get("if-none-match");
  const etag = await calculate(body);
  assert(etag);
  if (!ifNoneMatch(ifNoneMatchValue, etag)) {
    return new Response(null, { status: 304, headers: { etag } });
  } else {
    return new Response(body, { status: 200, headers: { etag } });
  }
});

Parameters

value: string | null
etag: string | undefined

Returns

boolean