Skip to content

Commit 3571ba0

Browse files
committed
Merge pull request dakrone#317 from MattParker89/empty-body-coercion
Fix issue dakrone#257
2 parents d47c5a6 + f28fa88 commit 3571ba0

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/clj_http/client.clj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,12 @@
346346
(defn coerce-clojure-body
347347
[request {:keys [body] :as resp}]
348348
(let [^String charset (or (-> resp :content-type-params :charset) "UTF-8")
349-
body (util/force-byte-array body)]
350-
(if edn-enabled?
351-
(assoc resp :body (parse-edn (String. ^"[B" body charset)))
352-
(binding [*read-eval* false]
353-
(assoc resp :body (read-string (String. ^"[B" body charset)))))))
349+
body (util/force-byte-array body)]
350+
(assoc resp :body (cond
351+
(empty? body) nil
352+
edn-enabled? (parse-edn (String. ^"[B" body charset))
353+
:else (binding [*read-eval* false]
354+
(read-string (String. ^"[B" body charset)))))))
354355

355356
(defn coerce-transit-body
356357
[{:keys [transit-opts] :as request} {:keys [body] :as resp} type]

test/clj_http/test/core_test.clj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,7 @@
565565
(run-server)
566566
(client/request {:method :get :url (localhost "/get") :headers {"foo" 2}}))
567567

568-
;; Currently failing, see: https://github.com/dakrone/clj-http/issues/257
569-
;; (deftest ^:integration t-empty-response-coercion
570-
;; (run-server)
571-
;; (let [resp (client/get (localhost "/empty") {:as :clojure})]
572-
;; (is (= (:body resp) ""))))
568+
(deftest ^:integration t-empty-response-coercion
569+
(run-server)
570+
(let [resp (client/get (localhost "/empty") {:as :clojure})]
571+
(is (= (:body resp) nil))))

0 commit comments

Comments
 (0)