Permalink
Browse files

wrap-cookies no longer overwrites any pre-set Set-Cookie headers

  • Loading branch information...
1 parent 812b240 commit d66cf3f352c1f99112c75e4e1737e415b168d005 @weavejester weavejester committed Nov 14, 2010
Showing with 11 additions and 3 deletions.
  1. +4 −3 ring-core/src/ring/middleware/cookies.clj
  2. +7 −0 ring-core/test/ring/middleware/cookies_test.clj
View
7 ring-core/src/ring/middleware/cookies.clj
@@ -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
View
7 ring-core/test/ring/middleware/cookies_test.clj
@@ -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.