Function eTag

  • Calculate an ETag for string or Uint8Array entities. This returns a strong tag of the form "<ascii chars>", which guarantees the byte-for-byte equality of the resource.

    You can optionally set true to the weak option to get a weak tag.

    Parameters

    • entity: string | Uint8Array

      The entity to get the ETag for.

    • Optionaloptions: ETagOptions

      Various additional options.

    Returns Promise<string>

    The calculated ETag.

    import { eTag } from "@std/http/etag";
    import { assert } from "@std/assert";

    const body = "hello deno!";

    const etag = await eTag(body);
    assert(etag);

    const res = new Response(body, { headers: { etag } });
  • Calculate an ETag for file information entity. This returns a weak tag of the form W\"<ascii chars>", which guarantees the equivalence of the resource, not the byte-for-byte equality.

    Parameters

    • entity: FileInfo

      The entity to get the ETag for.

    • Optionaloptions: ETagOptions

      Various additional options.

    Returns Promise<string | undefined>

    The calculated ETag.

    import { eTag } from "@std/http/etag";
    import { assert } from "@std/assert";

    const fileInfo = await Deno.stat("README.md");

    const etag = await eTag(fileInfo);
    assert(etag);

    using file = await Deno.open("README.md");

    const res = new Response(file.readable, { headers: { etag } });