diff options
author | Eduardo Julian | 2019-01-09 20:15:00 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-01-09 20:15:00 -0400 |
commit | aedd31b078d43d04e6877238c90d1db4021b5bf2 (patch) | |
tree | 5082f7be1d300eab5f79fb168e3e2a0f434b1d97 /stdlib/source | |
parent | 3821f5d988b632d5f0918cd752b65b7bf924d00e (diff) |
Added cookie support.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/world/net/http/cookie.lux | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/stdlib/source/lux/world/net/http/cookie.lux b/stdlib/source/lux/world/net/http/cookie.lux new file mode 100644 index 000000000..757d2abc8 --- /dev/null +++ b/stdlib/source/lux/world/net/http/cookie.lux @@ -0,0 +1,55 @@ +(.module: + [lux #* + [data + [text + format]] + [time + ["." duration (#+ Duration)]]] + ["." // (#+ Header) + ["." header]]) + +(type: #export Directive (-> Text Text)) + +(def: (directive extension) + (-> Text Directive) + (function (_ so-far) + (format so-far "; " extension))) + +(def: #export (set name value) + (-> Text Text Header) + (header.add "Set-Cookie" (format name "=" value))) + +(def: #export (max-age duration) + (-> Duration Directive) + (let [seconds (duration.query duration.second duration)] + (..directive (format "Max-Age=" (if (i/< +0 seconds) + (%i seconds) + (%n (.nat seconds))))))) + +(do-template [<name> <prefix>] + [(def: #export (<name> value) + (-> Text Directive) + (..directive (format <prefix> "=" value)))] + + [domain "Domain"] + [path "Path"] + ) + +(do-template [<name> <tag>] + [(def: #export <name> + Directive + (..directive <tag>))] + + [secure "Secure"] + [http-only "HttpOnly"] + ) + +(type: #export CSRF-Policy + #Strict + #Lax) + +(def: #export (same-site policy) + (-> CSRF-Policy Directive) + (..directive (format "SameSite=" (case policy + #Strict "Strict" + #Lax "Lax")))) |