Failing test with Rack::MockResponse #2204
Merged
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.
This PR removed checking for
transfer-encoding
from theRack::Response
object when deciding whether or not to set the content-length header. This had an impact on theRack::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 frombuffered_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