Function deleteCookie

  • Set the cookie header with empty value in the headers to delete it.

    The attributes (path, domain, secure, httpOnly, partitioned) need to match the values when the cookie was set.

    Note: Deleting a Cookie will set its expiration date before now. Forcing the browser to delete it.

    Parameters

    • headers: Headers

      The headers instance to delete the cookie from

    • name: string

      Name of cookie

    • Optionalattributes: Pick<Cookie,
          | "path"
          | "domain"
          | "secure"
          | "httpOnly"
          | "partitioned">

      Additional cookie attributes

    Returns void

    import { deleteCookie } from "@std/http/cookie";
    import { assertEquals } from "@std/assert";

    const headers = new Headers();
    deleteCookie(headers, "deno");

    const cookieHeader = headers.get("set-cookie");

    assertEquals(cookieHeader, "deno=; Expires=Thu, 01 Jan 1970 00:00:00 GMT");