Skip to content

Commit 6fab3e1

Browse files
authored
Buffer debug output to avoid mangling output (dakrone#544)
Fixes dakrone#536
1 parent 911f480 commit 6fab3e1

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/clj_http/core.clj

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -485,27 +485,29 @@
485485
(defn- print-debug!
486486
"Print out debugging information to *out* for a given request."
487487
[{:keys [debug-body body] :as req} http-req]
488-
(println "Request:" (type body))
489-
(clojure.pprint/pprint
490-
(assoc req
491-
:body (if (opt req :debug-body)
492-
(cond
493-
(isa? (type body) String)
494-
body
495-
496-
(isa? (type body) HttpEntity)
497-
(let [baos (ByteArrayOutputStream.)]
498-
(.writeTo ^HttpEntity body baos)
499-
(.toString baos "UTF-8"))
500-
501-
:else nil)
502-
(if (isa? (type body) String)
503-
(format "... %s bytes ..."
504-
(count body))
505-
(and body (bean body))))
506-
:body-type (type body)))
507-
(println "HttpRequest:")
508-
(clojure.pprint/pprint (bean http-req)))
488+
(println
489+
(with-out-str
490+
(println "Request:" (type body))
491+
(clojure.pprint/pprint
492+
(assoc req
493+
:body (if (opt req :debug-body)
494+
(cond
495+
(isa? (type body) String)
496+
body
497+
498+
(isa? (type body) HttpEntity)
499+
(let [baos (ByteArrayOutputStream.)]
500+
(.writeTo ^HttpEntity body baos)
501+
(.toString baos "UTF-8"))
502+
503+
:else nil)
504+
(if (isa? (type body) String)
505+
(format "... %s bytes ..."
506+
(count body))
507+
(and body (bean body))))
508+
:body-type (type body)))
509+
(println "HttpRequest:")
510+
(clojure.pprint/pprint (bean http-req)))))
509511

510512
(defn- build-response-map
511513
[^HttpResponse response req ^HttpUriRequest http-req http-url

0 commit comments

Comments
 (0)