Skip to content
Merged
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
Buffer debug output to avoid mangling output
Fixes #536
  • Loading branch information
Raymond Huang committed Jun 16, 2020
commit 37b8f06abe1951607b432c14a68734cd1c0ff17c
44 changes: 23 additions & 21 deletions src/clj_http/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -485,27 +485,29 @@
(defn- print-debug!
"Print out debugging information to *out* for a given request."
[{:keys [debug-body body] :as req} http-req]
(println "Request:" (type body))
(clojure.pprint/pprint
(assoc req
:body (if (opt req :debug-body)
(cond
(isa? (type body) String)
body

(isa? (type body) HttpEntity)
(let [baos (ByteArrayOutputStream.)]
(.writeTo ^HttpEntity body baos)
(.toString baos "UTF-8"))

:else nil)
(if (isa? (type body) String)
(format "... %s bytes ..."
(count body))
(and body (bean body))))
:body-type (type body)))
(println "HttpRequest:")
(clojure.pprint/pprint (bean http-req)))
(println
(with-out-str
(println "Request:" (type body))
(clojure.pprint/pprint
(assoc req
:body (if (opt req :debug-body)
(cond
(isa? (type body) String)
body

(isa? (type body) HttpEntity)
(let [baos (ByteArrayOutputStream.)]
(.writeTo ^HttpEntity body baos)
(.toString baos "UTF-8"))

:else nil)
(if (isa? (type body) String)
(format "... %s bytes ..."
(count body))
(and body (bean body))))
:body-type (type body)))
(println "HttpRequest:")
(clojure.pprint/pprint (bean http-req)))))

(defn- build-response-map
[^HttpResponse response req ^HttpUriRequest http-req http-url
Expand Down