Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serve Binary Content Using Clojure Ring

I wish to serve a PDF (or any other binary file) in a Clojure Ring response. This works

(defn serve-file [request]
  {:status 200
   :headers {"Content-Type" "application/pdf"}
   :body (FileInputStream. "file.pdf")})

But I'm not explicitly closing the FileInputStream. Will this cause a memory leak, or is it closed by the underlying web server (Jetty). If not, how do I close it myself?

like image 960
Matthew Molloy Avatar asked Jan 13 '13 10:01

Matthew Molloy


1 Answers

Yes, ring does close the InputStream object passed in body key.

Check out : https://github.com/mmcgrana/ring/blob/master/ring-servlet/src/ring/util/servlet.clj#L111

like image 136
Ankur Avatar answered Oct 26 '22 11:10

Ankur