Cookie
11/8/26Less than 1 minute
Cookie
Cookie object
@mptool/net creates and serializes cookies in the following object format:
name: cookie namevalue: cookie valuepath: cookie pathcreatedAt: creation time (millisecond timestamp)expires: expiration time (aDateobject)maxAge: maximum lifetime (seconds)domain: cookie domainsecure: whether the cookie is sent only over HTTPS (mini-programs support HTTPS only, and real devices can always send it; it is skipped only forhttp://debugging URLs)httpOnly: whether the cookie is used only over HTTPsameSite: the SameSite attribute (lax/strict/none), persisted with the cookie
name and value are required; all other fields are optional.
Cookie class
@mptool/net provides a Cookie class for working with cookie objects.
Constructor:
constructor(cookie: CookieType)cookie: the cookie object
Instance members:
name: string: cookie namevalue: string: cookie valuedomain: string: cookie domainpath: string: cookie pathcreatedAt: number: creation time (millisecond timestamp), used for RFC 6265 cookie orderingexpires: number | "session" | "outdate": expiration timehttpOnly: boolean: whether the cookie is used only over HTTP
Methods:
isExpired(): boolean: checks whether the cookie has expiredisPersistence(): boolean: checks whether the cookie can be persistedisDomainMatched(domain: string): boolean: checks whether the cookie matches a domaindomain: the domain
isPathMatched(path: string): boolean: checks whether the cookie matches a pathpath: the path
toString(): string: converts the cookie to a stringtoJSON(): CookieType: serializes the cookie to an object