Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to switch off keywordization of JSON-P responses. Fixes #86. #87

Merged
merged 1 commit into from
Dec 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/cljs_http/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,17 @@
(defn jsonp
"Execute the JSONP request corresponding to the given Ring request
map and return a core.async channel."
[{:keys [timeout callback-name cancel] :as request}]
[{:keys [timeout callback-name cancel keywordize-keys?]
:or {keywordize-keys? true}
:as request}]
(let [channel (async/chan)
jsonp (Jsonp. (util/build-url request) callback-name)]
(.setRequestTimeout jsonp timeout)
(let [req (.send jsonp nil
(fn success-callback [data]
(let [response {:status 200
:success true
:body (js->clj data :keywordize-keys true)}]
:body (js->clj data :keywordize-keys keywordize-keys?)}]
(async/put! channel response)
(swap! pending-requests dissoc channel)
(if cancel (async/close! cancel))
Expand Down
11 changes: 11 additions & 0 deletions test/cljs_http/test/client.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@
(is (= (:foo resp) "bar")))
(done)))))

(deftest ^:async test-keywordize-jsonp
(let [request (client/jsonp "http://jsfiddle.net/echo/jsonp/"
{:keywordize-keys? false
:query-params {:foo ""}
:channel (async/chan 1 (map :body))})]
(testing "JSON-P response keys aren't converted to keywords"
(go
(let [resp (async/<! request)]
(is (every? string? (keys resp))))
(done)))))

(deftest test-decode-body
(let [headers {"content-type" "application/transit+json"}
body "[\"^ \",\"~:a\",1]"
Expand Down