std/cookies

  Source   Edit

This module implements helper procs for parsing Cookies.

Types

SameSite {.pure.} = enum
  Default, None, Lax, Strict
The SameSite cookie attribute. Default means that setCookie proc will not set SameSite attribute.   Source   Edit

Procs

proc parseCookies(s: string): StringTableRef {....raises: [], tags: [].}

Parses cookies into a string table.

The proc is meant to parse the Cookie header set by a client, not the "Set-Cookie" header set by servers.

Example:

import std/strtabs
let cookieJar = parseCookies("a=1; foo=bar")
assert cookieJar["a"] == "1"
assert cookieJar["foo"] == "bar"
  Source   Edit
proc setCookie(key, value: string; domain = ""; path = ""; expires = "";
               noName = false; secure = false; httpOnly = false;
               maxAge = none(int); sameSite = SameSite.Default): string {.
    ...raises: [], tags: [].}
Creates a command in the format of Set-Cookie: key=value; Domain=...; ...   Source   Edit
proc setCookie(key, value: string; expires: DateTime | Time; domain = "";
               path = ""; noName = false; secure = false; httpOnly = false;
               maxAge = none(int); sameSite = SameSite.Default): string
Creates a command in the format of Set-Cookie: key=value; Domain=...; ...   Source   Edit