eudoxia0 / lucerne

A web framework for Common Lisp, built on Clack
http://borretti.me/lucerne/
142 stars 19 forks source link

Is there an easy way to set cookies #13

Open wnortje opened 8 years ago

wnortje commented 8 years ago

The only way I manage to set cookies is by doing this:

(defview page ()
   (list 200  
         (list :content-type "text"
               :set-cookie "sessionToken=abc123")
         (list "HI")))

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?

wnortje commented 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.

eudoxia0 commented 8 years ago

How would you like to do this? I think setting them in the response headers or the middleware is quite reasonable.

wnortje commented 8 years ago

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.

leinadlime commented 8 years ago

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 ;)