Skip to content

Commit 2e5aab8

Browse files
committed
fix nested form params with json encoding
1 parent 7d62d70 commit 2e5aab8

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

changelog.org

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@
136136
* Work log
137137
Log of merges/issues/work that's gone in so I know what to put in
138138
the changelog for the next release
139+
** 2012-05-07
140+
- fix json encoded form params with nested maps
139141
** 2012-05-02
140142
- fix attempted json coercion when a bad status is received
141143
** 2012-04-30

src/clj_http/client.clj

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@
354354
(let [[fk m] %]
355355
(reduce
356356
(fn [m [sk v]]
357-
(assoc m (str (name fk) \[ (name sk) \]) v))
357+
(assoc m (str (name fk)
358+
\[ (name sk) \]) v))
358359
{}
359360
m))
360361
%)
@@ -363,11 +364,13 @@
363364

364365
(defn wrap-nested-params
365366
[client]
366-
(fn [{:keys [query-params form-params] :as req}]
367-
(client (reduce
368-
nest-params
369-
req
370-
[:query-params :form-params]))))
367+
(fn [{:keys [query-params form-params content-type] :as req}]
368+
(if (= :json content-type)
369+
(client req)
370+
(client (reduce
371+
nest-params
372+
req
373+
[:query-params :form-params])))))
371374

372375
(defn wrap-url [client]
373376
(fn [req]

test/clj_http/test/core.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@
293293

294294
(deftest ^{:integration true} t-json-encoded-form-params
295295
(run-server)
296-
(let [params {:param1 "value1" :param2 "value2"}
296+
(let [params {:param1 "value1" :param2 {:foo "bar"}}
297297
resp (client/post (localhost "/post") {:content-type :json
298298
:form-params params})]
299299
(is (= 200 (:status resp)))

0 commit comments

Comments
 (0)