Skip to content

Commit

Permalink
Fixes a issue that happens when the response headers contains only on…
Browse files Browse the repository at this point in the history
…e 'set-cookie' entry.
  • Loading branch information
Cesar Canassa committed Feb 24, 2012
1 parent 0337e36 commit e139a02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/clj/http/async/client/headers.clj
Expand Up @@ -64,7 +64,8 @@
"Creates cookies from headers." "Creates cookies from headers."
[headers] [headers]
(if (contains? headers :set-cookie) (if (contains? headers :set-cookie)
(for [cookie-string (:set-cookie headers)] (for [cookie-string (let [set-cookie (:set-cookie headers)]
(if (string? set-cookie) (vector set-cookie) set-cookie))]
(let [name-token (atom true)] (let [name-token (atom true)]
(into {} (into {}
(for [#^String cookie (.split cookie-string ";")] (for [#^String cookie (.split cookie-string ";")]
Expand Down
12 changes: 11 additions & 1 deletion test/http/async/client/test.clj
Expand Up @@ -136,7 +136,7 @@
constraint (Constraint.) constraint (Constraint.)
mapping (ConstraintMapping.) mapping (ConstraintMapping.)
security (ConstraintSecurityHandler.)] security (ConstraintSecurityHandler.)]

(.addBean srv loginSrv) (.addBean srv loginSrv)
(doto constraint (doto constraint
(.setName Constraint/__BASIC_AUTH) (.setName Constraint/__BASIC_AUTH)
Expand Down Expand Up @@ -481,6 +481,16 @@
(is (thrown-with-msg? RuntimeException #"Too many connections 1" (GET client url))) (is (thrown-with-msg? RuntimeException #"Too many connections 1" (GET client url)))
(is (not (failed? (await r1))))))) (is (not (failed? (await r1)))))))



(deftest single-set-cookie
(let [resp (GET *client* "http://localhost:8123/cookie")
cookie (first (cookies resp))
header (headers resp)]
(is (string? (:set-cookie header)))
(is (= (:name cookie) "foo"))
(is (= (:value cookie) "bar"))))


(deftest await-string (deftest await-string
(let [resp (GET *client* "http://localhost:8123/stream") (let [resp (GET *client* "http://localhost:8123/stream")
body (string (await resp))] body (string (await resp))]
Expand Down

0 comments on commit e139a02

Please sign in to comment.