Support streaming #35

Closed
wants to merge 1 commit into
from

2 participants

@PaulSandoz

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"))))
@weavejester
Collaborator

This is a duplicate of pull request #5, and the same comment applies there as here.

  1. Any changes to the Ring SPEC should be proposed on the Ring group before being submitted as a pull request.
  2. I'm not going to merge such a significant change until after version 1.0.
@PaulSandoz

Thanks. Do you mean pull request #12 ?

#12

Definitely makes sense to step back and think a little more about this before committing to a solution.

@weavejester
Collaborator

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.

@weavejester
Collaborator

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