tcookies.nim 509 B

12345678910111213141516171819202122
  1. discard """
  2. targets: "c js"
  3. """
  4. import std/[cookies, times, strtabs]
  5. import std/assertions
  6. let expire = fromUnix(0) + 1.seconds
  7. let theCookies = [
  8. setCookie("test", "value", expire),
  9. setCookie("test", "value", expire.local),
  10. setCookie("test", "value", expire.utc)
  11. ]
  12. let expected = "Set-Cookie: test=value; Expires=Thu, 01 Jan 1970 00:00:01 GMT"
  13. doAssert theCookies == [expected, expected, expected]
  14. let table = parseCookies("uid=1; kp=2")
  15. doAssert table["uid"] == "1"
  16. doAssert table["kp"] == "2"