CookieJar
The cookies of one request: what arrived and what to send back.
The cookies of one request: what arrived and what to send back.
Import#
ts
import type { CookieJar } from "@shadow-js/dusk/server";
Signature#
ts
interface CookieJar {
/** Value of an incoming (or already set) cookie. */
get(name: string): string | undefined;
/** All cookies, name to value. */
getAll(): ReadonlyMap<string, string>;
/** Queues a `Set-Cookie`. Defaults: `Path=/; HttpOnly; Secure; SameSite=Lax`. */
set(name: string, value: string, options?: CookieOptions): void;
/** Queues a `Set-Cookie` that removes the cookie. Pass the `path` and `domain` it was set with. */
delete(
name: string,
options?: Pick<CookieOptions, "domain" | "path" | "secure" | "sameSite">,
): void;
/** Value of a signed cookie, or `undefined` when missing or when the signature does not verify. */
getSigned(name: string): Promise<string | undefined>;
/** Queues a signed cookie (HMAC-SHA-256 with the first configured secret). */
setSigned(name: string, value: string, options?: CookieOptions): Promise<void>;
/** The `Set-Cookie` header values queued so far. */
serialized(): readonly string[];
/**
* Whether a cookie that does not set `secure` is written with `Secure` on this request: true
* except in development over plain http on localhost. Code that picks a `__Host-` name reads it.
*/
readonly secure: boolean;
}
Members#
| Name | Type | Description |
|---|---|---|
get |
get(name: string): string | undefined |
Value of an incoming (or already set) cookie. |
getAll |
getAll(): ReadonlyMap<string, string> |
All cookies, name to value. |
set |
set(name: string, value: string, options?: CookieOptions): void |
Queues a Set-Cookie. Defaults: Path=/; HttpOnly; Secure; SameSite=Lax. |
delete |
delete( name: string, options?: Pick<CookieOptions, "domain" | "path" | "secure" | "sameSite">, ): void |
Queues a Set-Cookie that removes the cookie. Pass the path and domain it was set with. |
getSigned |
getSigned(name: string): Promise<string | undefined> |
Value of a signed cookie, or undefined when missing or when the signature does not verify. |
setSigned |
setSigned(name: string, value: string, options?: CookieOptions): Promise<void> |
Queues a signed cookie (HMAC-SHA-256 with the first configured secret). |
serialized |
serialized(): readonly string[] |
The Set-Cookie header values queued so far. |
secure |
readonly secure: boolean |
Whether a cookie that does not set secure is written with Secure on this request: true except in development over plain http on localhost. Code that picks a __Host- name reads it. |