aboutsummaryrefslogtreecommitdiffstats
path: root/src/types
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-06-25 10:54:25 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-25 10:54:43 +0200
commitfd837c155acca689839c5ce184fd5059caa83770 (patch)
tree1a6e42620a1a625ffad91f250f6d4782b2e83e26 /src/types
parent0461bbf6157fa4cfbc2c8054dc2c91d3593cad55 (diff)
downloadchawan-fd837c155acca689839c5ce184fd5059caa83770.tar.gz
cookie: return error on invalid domain
Diffstat (limited to 'src/types')
-rw-r--r--src/types/cookie.nim9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/types/cookie.nim b/src/types/cookie.nim
index a715ca8d..c6b526ee 100644
--- a/src/types/cookie.nim
+++ b/src/types/cookie.nim
@@ -2,6 +2,7 @@ import strutils
import times
import io/urlfilter
+import js/exception
import js/javascript
import js/regex
import types/url
@@ -202,7 +203,8 @@ proc serialize*(cookiejar: CookieJar, url: URL): string =
result &= "="
result &= cookie.value
-proc newCookie*(str: string, url: URL = nil): Cookie {.jsctor.} =
+proc newCookie*(str: string, url: URL = nil): Result[Cookie, JSError]
+ {.jsctor.} =
let cookie = new(Cookie)
cookie.expires = -1
cookie.created = now().toTime().toUnix()
@@ -246,8 +248,7 @@ proc newCookie*(str: string, url: URL = nil): Cookie {.jsctor.} =
cookie.domain = val
hasdomain = true
else:
- #TODO error, abort
- hasdomain = false
+ return err(newTypeError("Domains do not match"))
if not hasdomain:
if url != nil:
cookie.domain = url.host
@@ -256,7 +257,7 @@ proc newCookie*(str: string, url: URL = nil): Cookie {.jsctor.} =
cookie.path = "/"
else:
cookie.path = defaultCookiePath(url)
- return cookie
+ return ok(cookie)
proc newCookieJar*(location: URL, allowhosts: seq[Regex]): CookieJar =
return CookieJar(