From aedd31b078d43d04e6877238c90d1db4021b5bf2 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 9 Jan 2019 20:15:00 -0400 Subject: Added cookie support. --- stdlib/source/lux/world/net/http/cookie.lux | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 stdlib/source/lux/world/net/http/cookie.lux (limited to 'stdlib/source') 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 [ ] + [(def: #export ( value) + (-> Text Directive) + (..directive (format "=" value)))] + + [domain "Domain"] + [path "Path"] + ) + +(do-template [ ] + [(def: #export + Directive + (..directive ))] + + [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")))) -- cgit v1.2.3