hiredman/clj-http-lite

Unexpected nested form-params treatment

martinklepsch opened this issue · 0 comments

I bumped into something unexpected when switching from aleph to clj-http-lite. For some reason nested form params are sent differently despite their respective generate-query-string functions returning identical values.

The REPL session below makes this fairly easy to see by using httpbin.org:

;; boot -d aleph -d clj-http-lite repl

(def fp {"map" {"key1" "a", "key2" "b"}})

(require 'clj-http.lite.client 'aleph.http)

(= (aleph.http.client-middleware/generate-query-string fp)
   (clj-http.lite.client/generate-query-string fp))

(-> (clj-http.lite.client/post (str "https://httpbin.org/anything") {:accept "application/json" :form-params fp})
    :body cheshire.core/parse-string clojure.pprint/pprint)

(-> @(aleph.http/post (str "https://httpbin.org/anything") {:accept "application/json" :form-params fp})
    :body byte-streams/to-string cheshire.core/parse-string clojure.pprint/pprint)

If you manually account for the nesting as below things work as expected:

(def fp {"map[key1]" "a"
         "map[key2]" "b"})

It's fine to do the above but I'm just confused how :body is set to the same value that aleph would use in wrap-form-params and yet what is sent is somehow different.