Skip to content

Commit

Permalink
Close transit input stream after reading response (#565)
Browse files Browse the repository at this point in the history
Connections are not closing immediately after coercing the body using transit.
This is a regression introduced in #475.
Previously, the response body always was also transferred into an intermediate
byte-array which will read bytes until the stream is empty, and automatically
close the connection.

Since we no longer have this implicit behavior, the body coercion middleware
must close the inputstream after reading a value.

Fixes #564
  • Loading branch information
rymndhng authored Nov 15, 2020
1 parent d6d7255 commit 1a3bc03
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/clj_http/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@
{:pre [transit-enabled?]}
(let [charset (or charset (response-charset resp))
body (if (can-parse-body? request resp)
(parse-transit (util/force-stream body) type transit-opts)
(with-open [in (util/force-stream body)]
(parse-transit in type transit-opts))
(util/force-string body charset))]
(assoc resp :body body)))

Expand Down

0 comments on commit 1a3bc03

Please sign in to comment.