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

x/oak_http_proxy/test/deps.ts>Oak.etag.ifMatch

Proxy middleware for Deno Oak HTTP servers. 🐿 🦕
Latest
function Oak.etag.ifMatch
import { Oak } from "https://deno.land/x/oak_http_proxy@2.3.0/test/deps.ts";
const { ifMatch } = Oak.etag;

A helper function that takes the value from the If-Match header and a calculated etag for the target. By using strong comparison, return true if the values match, otherwise false.

See MDN's If-Match article for more information on how to use this function.

import {
  calculate,
  ifMatch,
} from "https://deno.land/std@0.224.0/http/etag.ts";
import { assert } from "https://deno.land/std@0.224.0/assert/assert.ts"

const body = "hello deno!";

Deno.serve(async (req) => {
  const ifMatchValue = req.headers.get("if-match");
  const etag = await calculate(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"});
  }
});

Parameters

value: string | null
etag: string | undefined

Returns

boolean