From 02874f575215f9665d99943a79541d4f849d50c3 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Thu, 24 Feb 2022 09:27:48 -0600 Subject: added server domain. set-cookie uses it if available. --- lazybones-hunchentoot.asd | 2 +- lazybones-hunchentoot.lisp | 31 ++++++++++++++++++++----------- lazybones.asd | 2 +- package.lisp | 1 + 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/lazybones-hunchentoot.asd b/lazybones-hunchentoot.asd index c44e927..4167cff 100644 --- a/lazybones-hunchentoot.asd +++ b/lazybones-hunchentoot.asd @@ -4,7 +4,7 @@ :description "hunchentoot backend for lazybones" :author "Colin Okay " :license "AGPLv3" - :version "0.1.2" + :version "0.2.0" :serial t :depends-on (#:hunchentoot #:lazybones) :components ((:file "lazybones-hunchentoot"))) diff --git a/lazybones-hunchentoot.lisp b/lazybones-hunchentoot.lisp index bb47d27..d39968f 100644 --- a/lazybones-hunchentoot.lisp +++ b/lazybones-hunchentoot.lisp @@ -41,7 +41,14 @@ :accessor canned-responses :initarg :canned-responses :initform nil - :documentation "an alist of (CODE CONTENT-FUNCTION CONTENT-TYPE)")) + :documentation "an alist of (CODE CONTENT-FUNCTION CONTENT-TYPE)") + (domain + :accessor server-domain + :initarg :domain + :initform nil + :documentation "A specific domain to associate with this server + for the purposes of cookie handling. NIL by default, which is + fine.")) (:default-initargs :address "127.0.0.1")) @@ -82,7 +89,7 @@ ;;; SERVER FUNCTIONS -(defun create-server (&key (port 8888) (address "127.0.0.1")) +(defun create-server (&key (port 8888) (address "127.0.0.1") ) "Creates an opaque server on port PORT, and returns it. Servers are backend specific, but each may be passed in to INSTALL-APP, UNINSTALL-APP, START-SERVER, and STOP-SERVER." @@ -256,15 +263,17 @@ the value of the Content-Type request header." (name value &key expires max-age path domain secure http-only (response lzb:*response*)) "Sets the response cookie" - (h:set-cookie name - :value value - :expires expires - :max-age max-age - :path path - :domain domain - :secure secure - :http-only http-only - :reply response)) + (apply 'h:set-cookie name + :value value + :reply response + (nconc (when expires (list :expires expires)) + (when max-age (list :max-age max-age)) + (when path (list :path path)) + (cond + (domain (list :domain domain)) + (server-domain (list :domain (server-domain)))) + (when secure (list :secure secure)) + (when http-only (list :http-only http-only))))) (defun http-respond (content &optional (code 200)) "Final step preparing response before backend does the rest. For diff --git a/lazybones.asd b/lazybones.asd index fcbce22..da9d921 100644 --- a/lazybones.asd +++ b/lazybones.asd @@ -4,7 +4,7 @@ :description "http route handling" :author "Colin Okay " :license "AGPLv3" - :version "0.8.0" + :version "0.9.0" :serial t :depends-on (#:alexandria #:str diff --git a/package.lisp b/package.lisp index 716c250..b11af58 100644 --- a/package.lisp +++ b/package.lisp @@ -27,6 +27,7 @@ #:install-app #:uninstall-app #:create-server + #:server-domain #:start-server #:stop-server #:canned-response -- cgit v1.2.3