summary refs log tree commit diff stats
path: root/lib/pure/cookies.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/cookies.nim')
-rw-r--r--lib/pure/cookies.nim11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/pure/cookies.nim b/lib/pure/cookies.nim
index 8d9cc0c95..f628aaf6b 100644
--- a/lib/pure/cookies.nim
+++ b/lib/pure/cookies.nim
@@ -11,6 +11,9 @@
 
 import std/[strtabs, times, options]
 
+when defined(nimPreviewSlimSystem):
+  import std/assertions
+
 
 type
   SameSite* {.pure.} = enum ## The SameSite cookie attribute.
@@ -25,7 +28,7 @@ proc parseCookies*(s: string): StringTableRef =
   ## "Set-Cookie" header set by servers.
   runnableExamples:
     import std/strtabs
-    let cookieJar = parseCookies("a=1; foo=bar") 
+    let cookieJar = parseCookies("a=1; foo=bar")
     assert cookieJar["a"] == "1"
     assert cookieJar["foo"] == "bar"
 
@@ -46,10 +49,12 @@ proc parseCookies*(s: string): StringTableRef =
 
 proc setCookie*(key, value: string, domain = "", path = "",
                 expires = "", noName = false,
-                secure = false, httpOnly = false, 
+                secure = false, httpOnly = false,
                 maxAge = none(int), sameSite = SameSite.Default): string =
   ## Creates a command in the format of
   ## `Set-Cookie: key=value; Domain=...; ...`
+  ##
+  ## .. tip:: Cookies can be vulnerable. Consider setting `secure=true`, `httpOnly=true` and `sameSite=Strict`.
   result = ""
   if not noName: result.add("Set-Cookie: ")
   result.add key & "=" & value
@@ -73,4 +78,4 @@ proc setCookie*(key, value: string, expires: DateTime|Time,
   ## `Set-Cookie: key=value; Domain=...; ...`
   result = setCookie(key, value, domain, path,
                    format(expires.utc, "ddd',' dd MMM yyyy HH:mm:ss 'GMT'"),
-                   noname, secure, httpOnly, maxAge, sameSite)
+                   noName, secure, httpOnly, maxAge, sameSite)