clj-http
clj-http copied to clipboard
Do I need to close the stream in case of exception?
According to the docs, when I receive a stream from the server, the connection hangs until I consume the whole stream:
;; Return the body as a stream
(client/get "http://example.com/bigrequest.html" {:as :stream})
;; Note that the connection to the server will NOT be closed until the
;; stream has been read
My question is, what will happen in case of non-200 exception? Do I still need to close the stream properly? I added the following code:
(try
(clj-http.client/get "http://non-existing-url" {:as :stream})
(catch Exception e
(some-> e ex-data :body .close)))
But I'm still not sure if I need that.
+1
Hi @igrishaev, clj-http doesn't do anything with the stream in the event that is a non-200 exception. In the event of a non-200 exception a user may still want to read from the stream (to get the body of the error for instance), so it doesn't automatically close.
Would you be willing to add something to the documentation about that?