Interface Cookie

Represents an HTTP Cookie.

interface Cookie {
    domain?: string;
    expires?: number | Date;
    httpOnly?: boolean;
    maxAge?: number;
    name: string;
    partitioned?: boolean;
    path?: string;
    sameSite?: "Strict" | "Lax" | "None";
    secure?: boolean;
    unparsed?: string[];
    value: string;
}

Properties

domain?: string

The cookie's Domain attribute. Specifies those hosts to which the cookie will be sent.

expires?: number | Date

The cookie's Expires attribute, either as an explicit date or UTC milliseconds. If undefined, the cookie will expire when the client's session ends.

import { Cookie } from "@std/http/cookie";
const cookie: Cookie = {
name: 'name',
value: 'value',
// expires on Fri Dec 30 2022
expires: new Date('2022-12-31')
}
import { Cookie } from "@std/http/cookie";
const cookie: Cookie = {
name: 'name',
value: 'value',
// expires 10 seconds from now
expires: Date.now() + 10000
}
httpOnly?: boolean

The cookie's HTTPOnly attribute. If true, the cookie cannot be accessed via JavaScript.

{false}
maxAge?: number

The cookie's Max-Age attribute, in seconds. Must be a non-negative integer. A cookie with a maxAge of 0 expires immediately.

name: string

Name of the cookie.

partitioned?: boolean

The cookie's Partitioned attribute. If true, the cookie will be only be included in the Cookie request header if the domain it is embedded by matches the domain the cookie was originally set from.

Warning: This is an attribute that has not been fully standardized yet. It may change in the future without following the semver semantics of the package. Clients may ignore the attribute until they understand it.

{false}
path?: string

The cookie's Path attribute. A cookie with a path will only be included in the Cookie request header if the requested URL matches that path.

sameSite?: "Strict" | "Lax" | "None"

Allows servers to assert that a cookie ought not to be sent along with cross-site requests.

secure?: boolean

The cookie's Secure attribute. If true, the cookie will only be included in the Cookie request header if the connection uses SSL and HTTPS.

{false}
unparsed?: string[]

Additional key value pairs with the form "key=value".

{[]}
value: string

Value of the cookie.