Module

std/http/cookie_map.ts>CookieMap

Deno standard library
Go to Latest
class CookieMap
extends CookieMapBase
import { CookieMap } from "https://dotland.deno.dev/std@0.181.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 {@link Map}. When constructing a {@link Request} or {@link Headers} from the request need to be provided, as well as optionally the {@link 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 {@link 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 {@link 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 {@link Request}. If the key is not present undefined is returned.

has(key: string): boolean

Returns true if the matching key is present in the {@link Request}, otherwise false.

keys(): IterableIterator<string>

Iterate over the cookie keys that are present in the {@link 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 {@link Request}.

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

Iterate over the cookie keys and values that are present in the {@link Request}.