Skip to content

Commit f0fca86

Browse files
committed
Fixed parse-cookies to cope with key-only cookies.
Previous parse-cookies would error out if cookie consisted only of a key; now the value for such a key will simply be nil. Also: slight rewrite of parse-cookies & parse-headers to use (more idiomatic, IMHO) (into {}) form for map construction.
1 parent b855c43 commit f0fca86

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/clojure/http/client.clj

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,17 @@ or the error stream of connection, whichever is appropriate."
6666
"Returns a map of the response headers from connection."
6767
[connection]
6868
(let [hs (.getHeaderFields connection)]
69-
(apply merge (map (fn [e] (when-let [k (key e)]
70-
{k (first (val e))}))
71-
hs))))
69+
(into {} (for [[k v] hs :when k] [k (first v)]))))
7270

7371
(defn- parse-cookies
7472
"Returns a map of cookies when given the Set-Cookie string sent
7573
by a server."
7674
[cookie-string]
7775
(when cookie-string
78-
(apply merge
79-
(map (fn [cookie]
80-
(apply hash-map
81-
(map (fn [c]
82-
(.trim c))
83-
(.split cookie "="))))
84-
(.split cookie-string ";")))))
76+
(into {}
77+
(for [cookie (.split cookie-string ";")]
78+
(let [keyval (map #(.trim %) (.split cookie "="))]
79+
[(first keyval) (second keyval)])))))
8580

8681
(defn- create-cookie-string
8782
"Returns a string suitable for sending to the server in the

0 commit comments

Comments
 (0)