diff options
author | bptato <nincsnevem662@gmail.com> | 2024-12-13 20:35:48 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-12-13 21:41:45 +0100 |
commit | 3757c1f7a97234b6659ce2f7b4cf2aada61a511a (patch) | |
tree | a462f67104af4f08e5f96f47649ea16411bb411c /src/types | |
parent | 2d060ddd47357cc4bb674bc0f5f604851f2f374c (diff) | |
download | chawan-3757c1f7a97234b6659ce2f7b4cf2aada61a511a.tar.gz |
cookie: remove JS module
I no longer need it
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/cookie.nim | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/src/types/cookie.nim b/src/types/cookie.nim index eb96ca62..113edd58 100644 --- a/src/types/cookie.nim +++ b/src/types/cookie.nim @@ -1,8 +1,7 @@ +import std/options import std/strutils import std/times -import monoucha/javascript -import monoucha/jserror import monoucha/jsregex import server/urlfilter import types/opt @@ -12,21 +11,19 @@ import utils/twtstr type Cookie* = ref object created: int64 # unix time - name {.jsget.}: string - value {.jsget.}: string - expires {.jsget.}: int64 # unix time - secure {.jsget.}: bool - httponly {.jsget.}: bool - samesite {.jsget.}: bool - domain {.jsget.}: string - path {.jsget.}: string + name: string + value: string + expires: int64 # unix time + secure: bool + httponly: bool + samesite: bool + domain: string + path: string CookieJar* = ref object filter*: URLFilter cookies*: seq[Cookie] -jsDestructor(Cookie) - proc parseCookieDate(val: string): Option[DateTime] = # cookie-date const Delimiters = {'\t', ' '..'/', ';'..'@', '['..'`', '{'..'~'} @@ -207,7 +204,7 @@ proc serialize*(cookiejar: CookieJar; url: URL): string = result &= "=" result &= cookie.value -proc newCookie*(str: string; url: URL = nil): JSResult[Cookie] {.jsctor.} = +proc newCookie*(str: string; url: URL): Opt[Cookie] = let cookie = Cookie(expires: -1, created: getTime().utc().toTime().toUnix()) var first = true var haspath = false @@ -241,29 +238,22 @@ proc newCookie*(str: string; url: URL = nil): JSResult[Cookie] {.jsctor.} = haspath = true cookie.path = val of "domain": - if url == nil or cookieDomainMatches(val, url): + if cookieDomainMatches(val, url): cookie.domain = val hasdomain = true else: - return errTypeError("Domains do not match") + return err() if not hasdomain: - if url != nil: - cookie.domain = url.host + cookie.domain = url.host if not haspath: - if url == nil: - cookie.path = "/" - else: - cookie.path = defaultCookiePath(url) + cookie.path = defaultCookiePath(url) return ok(cookie) -proc newCookieJar*(location: URL; allowhosts: seq[Regex]): CookieJar = +proc newCookieJar*(url: URL; allowhosts: seq[Regex]): CookieJar = return CookieJar( filter: newURLFilter( - scheme = some(location.scheme), - allowhost = some(location.host), + scheme = some(url.scheme), + allowhost = some(url.host), allowhosts = allowhosts ) ) - -proc addCookieModule*(ctx: JSContext) = - ctx.registerType(Cookie) |