Open wnortje opened 8 years ago
I managed to use session middleware for my purpose so my problem is resolved for now. I still think it should be easier to set custom cookies that what I described above.
How would you like to do this? I think setting them in the response headers or the middleware is quite reasonable.
What I showed breaks the high-level encapsulation of respond
, redirect
and render-template
because now you need to figure out exactly how Lucerne interacts with Clack. It is not difficult but it is not intuitive.
I expected an interface to clack.response:set-cookies
similar to lucerne:session
or otherwise a parameter to lucerne:respond
.
For adding http-readers, I redefined the RESPOND-function in the http-package. For setting a cookie, try this code before starting your lucerne-server:
(in-package :lucerne.http)
(defun respond (body &key (type "text/html;charset=utf-8") (status 200))
(list status
(list :content-type type :Set-Cookie "cookie-key=cookie-value")
(typecase body
(string (list body))
(otherwise body))))
UPDATE: it seems on a second read, that you don't really need this hint to achieve your goal. sorry for being overly helpful ;)
The only way I manage to set cookies is by doing this:
The session middleware doesn't do what I need and I can not find another way to set cookies.
Is this the recommended way or am I missing something?