diff options
Diffstat (limited to 'stdlib/source')
-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")))) |