Skip to content

Avoid response buffering for ISeq response body#528

Merged
weavejester merged 1 commit intoring-clojure:masterfrom
kumarshantanu:master
Jun 28, 2025
Merged

Avoid response buffering for ISeq response body#528
weavejester merged 1 commit intoring-clojure:masterfrom
kumarshantanu:master

Conversation

@kumarshantanu
Copy link
Contributor

This PR makes StreamableResponseBody implementation for ISeq avoid response buffering, which is useful when the ISeq elements are delayed at source. This also allows for a smooth Server-sent Events flow.

Consider the example usage below:

(defn make-seq []
  (Thread/sleep #_10 1000)
  (str "data: " (System/currentTimeMillis) "\n\n"))

(defn handler [request]
  {:status 200
   :headers {"Content-Type" "text/event-stream"}
   :body (repeatedly make-seq)})

@weavejester
Copy link
Member

Thanks for the update. Can you change the commit message to:

Flush response body stream when writing seqs

Update the StreamableResponseBody implementation for ISeq to flush the
OutputStream after each element. This prevents unnecessary delays when
dealing with blocking seqs, for example, when being used to implement
SSEs.

This makes it clearer which system is being affected by this change. There's no need to create a new PR for this - just --amend your commit message and then force push to update the PR.

@weavejester
Copy link
Member

Thanks for the update! Unfortunately I didn't notice this change before I added to the tests (GitHub only notifies me about comments, not new commits), so there's a minor conflict in the test file. Can you rebase and fix it, then I'll go ahead and merge it ready for Ring 1.15.0.

Update the StreamableResponseBody implementation for ISeq to flush the
OutputStream after each element. This prevents unnecessary delays when
dealing with blocking seqs, for example, when being used to implement
SSEs.
@kumarshantanu
Copy link
Contributor Author

kumarshantanu commented Jun 28, 2025

@weavejester Thanks for considering the PR! I have rebased and fixed it.

@weavejester weavejester merged commit 4d3f49a into ring-clojure:master Jun 28, 2025
1 check passed
@weavejester
Copy link
Member

Merged. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants