Support streaming #35
This is a duplicate of pull request #5, and the same comment applies there as here.
- Any changes to the Ring SPEC should be proposed on the Ring group before being submitted as a pull request.
- I'm not going to merge such a significant change until after version 1.0.
Uh, yeah. I'm not sure how I managed to get those numbers mixed up! I thought I copy-pasted.
I think I'm actually in favor of this change, but it'll probably need to wait for version 1.1, as I want to focus on getting the remaining issues for 1.0 done with first.
I think I'm going to implement this functionality via a function, rather than an alteration to the SPEC.
Something like:
(response (piped-input-stream (fn [out-stream] ...)))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The body can be a Fn that takes one argument that is the java.io.OutputStream to write the entity. This allows for streaming, for example, in conjunction with Compojure, an image does not need to be written to an ByteArrayOutputStream then those bytes copied to a ByteArrayInputStream, and then those bytes copied again to the servlet OutputStream:
(extend-protocol Renderable BufferedImage (render [image _] (-> (ring.util.response/response #(ImageIO/write image "png" %1)) (ring.util.response/content-type "image/png"))))