Cookie

import { Cookie } from "jsr:@ende/http";

interface

interface Cookie

Represents an HTTP Cookie.

See also

Properties

name

name: string

Name of the cookie.

value

value: string

Value of the cookie.

expires

expires?: Date | number

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.

Example: Explicit date:

import { Cookie } from "@ende/http/cookie";
const cookie: Cookie = {
  name: 'name',
  value: 'value',
  // expires on Fri Dec 30 2022
  expires: new Date('2022-12-31')
}

Example: UTC milliseconds

import { Cookie } from "@ende/http/cookie";
const cookie: Cookie = {
  name: 'name',
  value: 'value',
  // expires 10 seconds from now
  expires: Date.now() + 10000
}

maxAge

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.

domain

domain?: string

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

path

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.

secure

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.

Default: false

httpOnly

httpOnly?: boolean

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

Default: false

partitioned

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.

Default: false

sameSite

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

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

unparsed

unparsed?: string[]

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

Default: []

Source