Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing test with Rack::MockResponse #2204

Merged
merged 2 commits into from
Jun 11, 2024

Conversation

tenderlove
Copy link
Member

@tenderlove tenderlove commented Jun 11, 2024

This PR removed checking for transfer-encoding from the Rack::Response object when deciding whether or not to set the content-length header. This had an impact on the Rack::MockResponse subclass as the mock response subclass will try to buffer the response immediately inside the initialize method. When the response is buffered, the @length instance variable is set, and this causes the superclass to set the content-length header even though it's a streaming response.

I'm unsure how to fix this situation, so this PR is just a failing test that demonstrates the problematic behavior. Even though the chunked body object doesn't respond to to_ary, the mock response object decides to buffer it anyway, causing the "content length" header to be set. I tried returning early from buffered_body!, but this causes other issues surrounding when the body should be "closed" (it turns tests will try to read the response body twice, but the second time it is closed).

Ref: rails/rails#52066
Ref: rails/rails#52092

@tenderlove tenderlove added the Bug label Jun 11, 2024
@jeremyevans
Copy link
Contributor

I propose reverting #2195 to fix the issue. When I approved it, I was not aware of what was depending on the previous behavior.

@tenderlove
Copy link
Member Author

I propose reverting #2195 to fix the issue. When I approved it, I was not aware of what was depending on the previous behavior.

Ya, I think we should. I agree that theoretically #2195 is the right thing to do, but it seems like we need to take more situations in to account before we can do it. "Testing + streaming responses" seems like perilous territory and we should figure out what to do there before we redo #2195

@tenderlove tenderlove mentioned this pull request Jun 11, 2024
@tenderlove tenderlove enabled auto-merge (rebase) June 11, 2024 19:54
@tenderlove tenderlove disabled auto-merge June 11, 2024 19:55
@tenderlove tenderlove merged commit 3440283 into rack:main Jun 11, 2024
15 checks passed
@tenderlove tenderlove deleted the buffered-response branch June 11, 2024 19:59
tenderlove added a commit that referenced this pull request Jun 11, 2024
* Failing test with Rack::MockResponse

* Revert "Remove any dependeny on `transfer-encoding` / `chunked`. (#2195)"

This reverts commit e1f5683.
@ioquatix
Copy link
Member

and this causes the superclass to set the content-length header even though it's a streaming response.

By the time Rack::MockResponse gets the body, and processes it, it's no longer streaming, because Rack::MockResponse behaves like a client and reads all the chunks into a single buffer. I'm not sure if this is the correct behaviour or not, but it seems reasonable to me. However, as we can see, it's also problematic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants