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

std/http/cookie_map.ts>CookieMap

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
class CookieMap
extends CookieMapBase
import { CookieMap } from "https://deno.land/std@0.203.0/http/cookie_map.ts";

Provides a way to manage cookies in a request and response on the server as a single iterable collection.

The methods and properties align to Map. When constructing a Request or Headers from the request need to be provided, as well as optionally the Response or Headers for the response can be provided. Alternatively the mergeHeaders function can be used to generate a final set of headers for sending in the response.

Constructors

new
CookieMap(request: Headers | Headered, options?: CookieMapOptions)

Properties

readonly
size: number

Contains the number of valid cookies in the request headers.

Methods

Deletes all the cookies from the Request in the response.

delete(key: string, options?: CookieMapSetDeleteOptions): boolean

Set a cookie to be deleted in the response.

This is a convenience function for set(key, null, options?).

entries(): IterableIterator<[string, string]>

Iterate over the cookie keys and values that are present in the Request. This is an alias of the [Symbol.iterator] method present on the class.

get(key: string): string | undefined

Return the value of a matching key present in the Request. If the key is not present undefined is returned.

has(key: string): boolean

Returns true if the matching key is present in the Request, otherwise false.

keys(): IterableIterator<string>

Iterate over the cookie keys that are present in the Request.

set(
key: string,
value: string | null,
): this

Set a named cookie in the response. The optional CookieMapSetDeleteOptions are applied to the cookie being set.

values(): IterableIterator<string>

Iterate over the cookie values that are present in the Request.

[Symbol.iterator](): IterableIterator<[string, string]>

Iterate over the cookie keys and values that are present in the Request.