mirror of
https://github.com/vale981/lack
synced 2025-03-05 09:21:39 -05:00
Merge pull request #3 from andy128k/session-with-delayed-response
allow session middleware to wrap delayed response
This commit is contained in:
commit
460e73890c
3 changed files with 39 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
|||
language: common-lisp
|
||||
sudo: required
|
||||
|
||||
env:
|
||||
matrix:
|
||||
|
|
|
@ -35,7 +35,12 @@
|
|||
(setf (cookie-state-expires state) 0)
|
||||
(finalize-state state sid res options))
|
||||
|
||||
(defmethod finalize-state ((state cookie-state) sid res options)
|
||||
(defmethod finalize-state ((state cookie-state) sid (res function) options)
|
||||
(lambda (responder)
|
||||
(funcall res (lambda (actual-res)
|
||||
(funcall responder (finalize-state state sid actual-res options))))))
|
||||
|
||||
(defmethod finalize-state ((state cookie-state) sid (res list) options)
|
||||
(let ((res (apply #'make-response res))
|
||||
(options (append (remove-from-plist options :id)
|
||||
(with-slots (path domain expires secure httponly) state
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
:lack.test))
|
||||
(in-package :t.lack.middleware.session)
|
||||
|
||||
(plan 2)
|
||||
(plan 3)
|
||||
|
||||
(ok (lack.session.state:make-state)
|
||||
"Base class of session state")
|
||||
|
@ -38,4 +38,35 @@
|
|||
(is status 200)
|
||||
(is body '("Hello, you've been here for 2th times!")))))
|
||||
|
||||
(subtest "session with delayed response"
|
||||
(let ((app
|
||||
(builder
|
||||
:session
|
||||
(lambda (env)
|
||||
(unless (gethash :counter (getf env :lack.session))
|
||||
(setf (gethash :counter (getf env :lack.session)) 0))
|
||||
(lambda (responder)
|
||||
(funcall responder
|
||||
`(200
|
||||
(:content-type "text/plain")
|
||||
(,(format nil "Hello, you've been here for ~Ath times!"
|
||||
(incf (gethash :counter (getf env :lack.session)))))))))))
|
||||
session)
|
||||
(diag "1st request")
|
||||
(funcall (funcall app (generate-env "/"))
|
||||
(lambda (response)
|
||||
(destructuring-bind (status headers body) response
|
||||
(is status 200)
|
||||
(setf session (parse-lack-session headers))
|
||||
(ok session)
|
||||
(is body '("Hello, you've been here for 1th times!")))))
|
||||
|
||||
(diag "2nd request")
|
||||
(funcall (funcall app (generate-env "/" :cookies `(("lack.session" . ,session))))
|
||||
(lambda (response)
|
||||
(destructuring-bind (status headers body) response
|
||||
(declare (ignore headers))
|
||||
(is status 200)
|
||||
(is body '("Hello, you've been here for 2th times!")))))))
|
||||
|
||||
(finalize)
|
||||
|
|
Loading…
Add table
Reference in a new issue