diff options
author | Oscar Nihlgård <oscarnihlgard@gmail.com> | 2018-04-03 12:15:01 +0200 |
---|---|---|
committer | Oscar Nihlgård <oscarnihlgard@gmail.com> | 2018-04-03 12:15:01 +0200 |
commit | 97565826efbc9e551829531875867c8f78378691 (patch) | |
tree | f9be8241403f589f015eaa3277bd8d43bbb613d8 /lib/pure | |
parent | 5ea80b43b1805003d8c06ac5122c6e698c959f52 (diff) | |
download | Nim-97565826efbc9e551829531875867c8f78378691.tar.gz |
Don't assume UTC in cookies.setCookie
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/cookies.nim | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/pure/cookies.nim b/lib/pure/cookies.nim index 8f16717ac..aca0ac2b4 100644 --- a/lib/pure/cookies.nim +++ b/lib/pure/cookies.nim @@ -51,26 +51,26 @@ proc setCookie*(key, value: string, domain = "", path = "", if secure: result.add("; Secure") if httpOnly: result.add("; HttpOnly") -proc setCookie*(key, value: string, expires: DateTime, +proc setCookie*(key, value: string, expires: DateTime|Time, 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 'GMT'"), + format(expires.utc, "ddd',' dd MMM yyyy HH:mm:ss 'GMT'"), noname, secure, httpOnly) when isMainModule: - var tim = fromUnix(getTime().toUnix + 76 * (60 * 60 * 24)) + let expire = fromUnix(0) + 1.seconds - let cookie = setCookie("test", "value", tim.utc) - when not defined(testing): - echo cookie - let start = "Set-Cookie: test=value; Expires=" - assert cookie[0..start.high] == start + let cookies = [ + setCookie("test", "value", expire), + setCookie("test", "value", expire.local), + setCookie("test", "value", expire.utc) + ] + let expected = "Set-Cookie: test=value; Expires=Thu, 01 Jan 1970 00:00:01 GMT" + doAssert cookies == [expected, expected, expected] let table = parseCookies("uid=1; kp=2") - assert table["uid"] == "1" - assert table["kp"] == "2" + doAssert table["uid"] == "1" + doAssert table["kp"] == "2" |