Update ActionDispatch::Response to support streaming bodies.#47092
Merged
tenderlove merged 1 commit intorails:mainfrom Feb 15, 2023
Merged
Update ActionDispatch::Response to support streaming bodies.#47092tenderlove merged 1 commit intorails:mainfrom
ActionDispatch::Response to support streaming bodies.#47092tenderlove merged 1 commit intorails:mainfrom
Conversation
Contributor
Author
|
I think this is an area that we want to refactor in Rails 8. There is a lot of cruft, and this mostly just does the bare minimum to get things working. |
Rack 3 introduces streaming bodies, which don't respond to `#each` and MUST respond to `#call`. Ensure that the methods are correctly delegated. `#to_ary` must also work correctly for enumerable bodies, and is used by middleware like `Rack::ETag` to buffer enumerable bodies correctly.
aad1d39 to
89df368
Compare
Contributor
Author
|
@rafaelfranca this is also another relatively straight forward one which aligns |
ioquatix
commented
Jan 25, 2023
| @@ -396,9 +396,9 @@ def test_only_set_charset_still_defaults_to_text_html | |||
| test "[response.to_a].flatten does not recurse infinitely" do | |||
| Timeout.timeout(1) do # use a timeout to prevent it stalling indefinitely | |||
| status, headers, body = [@response.to_a].flatten | |||
Contributor
Author
There was a problem hiding this comment.
This issue was actually resolved in Rack 3 and is no longer possible due to an updated SPEC (IIRC), so in theory we could just remove this entire test.
JoeDupuis
added a commit
to JoeDupuis/rails
that referenced
this pull request
Jun 11, 2023
Changes to support Rack 3 broke Streaming responses rails#47092 Streaming responses are failing with undefined method `to_ary' Live::Response should not respond to `to_ary` since they cannot be buffered safely.
zzak
added a commit
to zzak/rails
that referenced
this pull request
Oct 13, 2023
The downside to this is that we cannot generate ETags for these types of responses, but are assuming that by using an enumerator they don't expect a buffered response to be cacheable. This means you cannot use Enumerator to generate streaming responses. Fixes rails#49588 See also: rails#47092 Co-authored-by: Samuel Williams <samuel.williams@oriontransfer.co.nz>
zzak
added a commit
to zzak/rails
that referenced
this pull request
Oct 13, 2023
There is an inherit complexity with wrapping the Rack body inside Rails which can lead to bugs, like rails#49588. While rails#49616 fixed the bug, it's probably not a good long-term solution. If we go all the way back to 6a89850, we can see this was the original behavior. However, we were trying to solve a separate issue with streaming bodies during disconnect. The `live_stream_test#test_abort_with_full_buffer` test fails in this PR, but I wanted to raise that maybe this could be handled a different way. Also there are two failures in `response_test` which are questions to me: * `ResponseTest#test_[response.to_a].flatten_does_not_recurse_infinitely` * `ResponseTest#test_compatibility_with_Rack::ContentLength` The first seems it is actually resolved upstream, per this comment: rails#47092 (comment) The second means we broke `Rack::ContentLength` and there is a bit on this in rails#44953. FWIW: I'm not proposing this PR exactly, but looking for a path forward and would love some feedback. 🙇
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rack 3 introduces streaming bodies, which don't respond to
#eachand MUST respond to#call. Ensure that the methods are correctly delegated.#to_arymust also work correctly for enumerable bodies, and is used by middleware likeRack::ETagto buffer enumerable bodies correctly.