What is the difference between:
(def app
(wrap-session handler))
and
(defn app-bad [request]
((wrap-session handler) request))
?
I was thinking that the second exactly the same function - but apparently in that case the wrapper sets a new session cookie on each request. When I reload the page and view the headers I can see that each response has a Set-Cookie header for 'ring-session' - with a new hash:
Set-Cookie:ring-session=db84a908-6b08-4ae6-863e-de7a2cd2df5d;Path=/
I was doing that 'defn' definition for debugging - I wanted to see the request before the middlewares.
Here is the full program:
(ns ring-session-test.core)
(use 'ring.middleware.session)
(defn handler [request]
(println (request :session))
{:status 200
:headers {"Content-Type" "text/plain"}
:body "Text"
:session {:a (rand)}})
(def app
(wrap-session handler))
(defn app-bad [request]
((wrap-session handler) request))
And my project.clj:
(defproject ring-session-test "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:license {:name "Eclipse Public License"
:dependencies [[org.clojure/clojure "1.4.0"]
[ring/ring-core "1.1.6"]
[ring/ring-jetty-adapter "1.1.6"]]
:plugins [[lein-ring "0.8.2"]]
:ring {:handler ring-session-test.core/app-bad})
I run it with 'lein ring server'.
Cheers,
Zbigniew