Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
class CookieMap
extends CookieMapBase
Deprecated
Deprecated

(will be removed in 0.212.0) Use https://deno.land/std/http/cookie.ts instead.

import { CookieMap } from "https://deno.land/std@0.211.0/http/unstable_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.