mirror of
https://github.com/vale981/lack
synced 2025-03-06 01:41: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
|
language: common-lisp
|
||||||
|
sudo: required
|
||||||
|
|
||||||
env:
|
env:
|
||||||
matrix:
|
matrix:
|
||||||
|
|
|
@ -35,7 +35,12 @@
|
||||||
(setf (cookie-state-expires state) 0)
|
(setf (cookie-state-expires state) 0)
|
||||||
(finalize-state state sid res options))
|
(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))
|
(let ((res (apply #'make-response res))
|
||||||
(options (append (remove-from-plist options :id)
|
(options (append (remove-from-plist options :id)
|
||||||
(with-slots (path domain expires secure httponly) state
|
(with-slots (path domain expires secure httponly) state
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
:lack.test))
|
:lack.test))
|
||||||
(in-package :t.lack.middleware.session)
|
(in-package :t.lack.middleware.session)
|
||||||
|
|
||||||
(plan 2)
|
(plan 3)
|
||||||
|
|
||||||
(ok (lack.session.state:make-state)
|
(ok (lack.session.state:make-state)
|
||||||
"Base class of session state")
|
"Base class of session state")
|
||||||
|
@ -38,4 +38,35 @@
|
||||||
(is status 200)
|
(is status 200)
|
||||||
(is body '("Hello, you've been here for 2th times!")))))
|
(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)
|
(finalize)
|
||||||
|
|
Loading…
Add table
Reference in a new issue