summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2014-09-01 00:28:17 +0200
committerAndreas Rumpf <rumpf_a@web.de>2014-09-01 00:28:17 +0200
commit1c85a49e6b4ede5a58067a5405e8e6b40e53e241 (patch)
tree4fbd5e91f554de7456a4f67045821335793a5dde /lib/pure
parentcb9f6698639dd51bcff80ef2ed2f71621cdaf414 (diff)
parenta249a12da7d1868176788e3bc1627f76aa9977e8 (diff)
downloadNim-1c85a49e6b4ede5a58067a5405e8e6b40e53e241.tar.gz
Merge pull request #1509 from idlewan/cookies
Secure and HttpOnly cookies
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/cookies.nim15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/pure/cookies.nim b/lib/pure/cookies.nim
index d1cf36a87..49bf92980 100644
--- a/lib/pure/cookies.nim
+++ b/lib/pure/cookies.nim
@@ -28,8 +28,9 @@ proc parseCookies*(s: string): PStringTable =
     if s[i] == '\0': break
     inc(i) # skip ';'
 
-proc setCookie*(key, value: string, domain = "", path = "", 
-                expires = "", noName = false): string =
+proc setCookie*(key, value: string, domain = "", path = "",
+                expires = "", noName = false,
+                secure = false, httpOnly = false): string =
   ## Creates a command in the format of 
   ## ``Set-Cookie: key=value; Domain=...; ...``
   result = ""
@@ -38,16 +39,20 @@ proc setCookie*(key, value: string, domain = "", path = "",
   if domain != "": result.add("; Domain=" & domain)
   if path != "": result.add("; Path=" & path)
   if expires != "": result.add("; Expires=" & expires)
+  if secure: result.add("; secure")
+  if httpOnly: result.add("; HttpOnly")
 
 proc setCookie*(key, value: string, expires: TTimeInfo,
-                domain = "", path = "", noName = false): string =
+                domain = "", path = "", noName = false,
+                secure = false, httpOnly = false): string =
   ## Creates a command in the format of 
   ## ``Set-Cookie: key=value; Domain=...; ...``
   ##
   ## **Note:** UTC is assumed as the timezone for ``expires``.
   
   return setCookie(key, value, domain, path,
-            format(expires, "ddd',' dd MMM yyyy HH:mm:ss 'UTC'"), noname)
+                   format(expires, "ddd',' dd MMM yyyy HH:mm:ss 'UTC'"),
+                   noname, secure, httpOnly)
   
 when isMainModule:
   var tim = TTime(int(getTime()) + 76 * (60 * 60 * 24))
@@ -55,5 +60,3 @@ when isMainModule:
   echo(setCookie("test", "value", tim.getGMTime()))
   
   echo parseCookies("uid=1; kp=2")
-  
-                
\ No newline at end of file