cookie module

Parse Cookie: headers into maps, and build Set-Cookie header values with the right attributes.

import "cookie" as cookie;

var parsed = cookie.parse("theme=dark; lang=en; sid=abc123");
print(parsed.theme);     // dark

var sc = cookie.build("sid", "abc123", {
    path: "/", http_only: true, max_age: 3600, same_site: "Lax"
});
// sid=abc123; Path=/; HttpOnly; Max-Age=3600; SameSite=Lax

API

FunctionDescription
cookie.parse(header) → mapParse a Cookie: header value into {name: value, …}.
cookie.build(name, value, opts) → stringBuild a Set-Cookie value. opts: {path, domain, max_age, expires, http_only, secure, same_site}.
cookie.delete_(name, opts) → stringBuild a cookie that expires immediately — use to log out / clear a cookie on the client.

See also

  • session — session middleware built on top of cookie.
  • webreq.cookies is already a parsed map.