web/cookie: improvements: create-from-keys, more default values

This commit is contained in:
Helmut Merz 2024-09-02 10:39:44 +02:00
parent 1e6ffc1fa2
commit b4fc8ad05d
2 changed files with 10 additions and 7 deletions

View file

@ -3,14 +3,18 @@
(defpackage :scopes/web/cookie (defpackage :scopes/web/cookie
(:use :common-lisp) (:use :common-lisp)
(:local-nicknames (:c cl-cookie)) (:local-nicknames (:c cl-cookie))
(:export #:create #:make-header)) (:export #:create #:create-from-keys #:make-header))
(in-package :scopes/web/cookie) (in-package :scopes/web/cookie)
(defun create (name value &key max-age (path "/") (httponly-p t)) (defun create (name value &rest args &key &allow-other-keys)
(c:make-cookie :name name :value value (apply #'create-from-keys :name name :value value args))
:path path :httponly-p httponly-p
:max-age max-age)) (defun create-from-keys (&key name value domain (same-site :lax)
(max-age 86400) (path "/") (httponly-p t)
&allow-other-keys)
(c:make-cookie :name name :value value :domain domain :same-site same-site
:max-age max-age :path path :httponly-p httponly-p))
(defun make-header (cookie) (defun make-header (cookie)
(c:write-set-cookie-header cookie)) (c:write-set-cookie-header cookie))

View file

@ -38,9 +38,8 @@
(shape:print-fields ia s 'messages)) (shape:print-fields ia s 'messages))
(defun render-cookie (cdata) (defun render-cookie (cdata)
(let ((cookie (cookie:create (getf cdata :name) (getf cdata :value)))) (let ((cookie (apply #'cookie:create-from-keys cdata)))
(cookie:make-header cookie))) (cookie:make-header cookie)))
;"DEMO=1234567_value; Path=/") ;"; Domain=testing.cyberscopes.org")
;;;; response definitions ;;;; response definitions