Failing test with Rack::MockResponse#2204
Conversation
|
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 |
By the time |
This PR removed checking for
transfer-encodingfrom theRack::Responseobject when deciding whether or not to set the content-length header. This had an impact on theRack::MockResponsesubclass as the mock response subclass will try to buffer the response immediately inside the initialize method. When the response is buffered, the@lengthinstance 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