Skip to content

Commit

Permalink
wrap-cookies no longer overwrites any pre-set Set-Cookie headers
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Nov 14, 2010
1 parent 812b240 commit d66cf3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ring-core/src/ring/middleware/cookies.clj
Expand Up @@ -115,9 +115,10 @@
"Add a Set-Cookie header to a response if there is a :cookies key."
[response]
(if-let [cookies (:cookies response)]
(assoc-in response
[:headers "Set-Cookie"]
(write-cookies cookies))
(update-in response
[:headers "Set-Cookie"]
concat
(write-cookies cookies))
response))

(defn wrap-cookies
Expand Down
7 changes: 7 additions & 0 deletions ring-core/test/ring/middleware/cookies_test.clj
Expand Up @@ -71,3 +71,10 @@
resp ((wrap-cookies handler) {})]
(is (= {"Set-Cookie" (list "a=hello+world")}
(:headers resp)))))

(deftest wrap-cookies-keep-set-cookies-intact
(let [handler (constantly {:headers {"Set-Cookie" (list "a=b")}
:cookies {:c "d"}})
resp ((wrap-cookies handler) {})]
(is (= {"Set-Cookie" (list "a=b" "c=d")}
(:headers resp)))))

0 comments on commit d66cf3f

Please sign in to comment.