Skip to content

Commit 00f6ed8

Browse files
committed
fix with-cookies macro. Thanks to Perry Trolard
1 parent de22ee3 commit 00f6ed8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/clojure/http/resourcefully.clj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
(defn- error? [response]
3232
(>= (:code response) 400))
3333

34-
(defn error-message [response]
34+
(defn- error-message [response]
3535
(str "Problem with " (:url response) ": "
3636
(:code response) " "
3737
(:msg response) "\n"
@@ -44,7 +44,9 @@
4444
map. Cookies will be saved if inside with-cookies block.")
4545
[u# & [headers# body#]]
4646
(let [response# (save-cookies (client/request u# ~(str method)
47-
headers# *cookies* body#))]
47+
headers# (if *cookies*
48+
@*cookies*)
49+
body#))]
4850
(if (error? response#)
4951
(throw (java.io.IOException. (error-message response#)))
5052
response#))))
@@ -56,8 +58,9 @@ map. Cookies will be saved if inside with-cookies block.")
5658
(define-method head)
5759

5860
(defmacro with-cookies
59-
"Perform body with *cookies* bound to cookie-map. Responses that set
60-
cookies will have them saved in the *cookies* ref."
61+
"Perform body with *cookies* bound to cookie-map (should be a map;
62+
empty if you don't want any initial cookies). Responses that set cookies
63+
will have them saved in the *cookies* ref."
6164
[cookie-map & body]
62-
`(binding [*cookies* (ref (or cookie-map {}))]
65+
`(binding [*cookies* (ref (or ~cookie-map {}))]
6366
~@body))

0 commit comments

Comments
 (0)