Skip to content

Only digest body when body.to_ary is present#1876

Closed
st0012 wants to merge 1 commit intorack:mainfrom
st0012:fix-etags
Closed

Only digest body when body.to_ary is present#1876
st0012 wants to merge 1 commit intorack:mainfrom
st0012:fix-etags

Conversation

@st0012
Copy link
Copy Markdown

@st0012 st0012 commented Apr 23, 2022

Since #1748, the result of body.to_ary will be sent directly into digest_body for generating etag digest. But ActionDispatch::Response::RackBody#to_ary always returns nil, which will cause NoMethodError with this approach. Therefore, I think it makes sense to check if the result of body.to_ary is present before trying to generate digest from it.

(It wasn't an issue before #1748 because Rack used to pass the body (responds to #each) to digest_body instead).

@jeremyevans
Copy link
Copy Markdown
Contributor

The Rack 3 SPEC is that if body responds to to_ary, then to_ary needs to return an array:

If the Body responds to +to_ary+, it must return an Array whose
contents are identical to that produced by calling +each+.

We don't want everything that interacts with the body have to defensively check to see whether to_ary returns an array. So ActionDispatch::Response::RackBody needs to be fixed to work with Rack 3.

@st0012 st0012 deleted the fix-etags branch April 23, 2022 17:15
@st0012
Copy link
Copy Markdown
Author

st0012 commented Apr 23, 2022

@jeremyevans Sorry I didn't see that. I'll leave Rails team to make it compatible then, thx!

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