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

Handle ActionDispatch::Response::RackBody as body #22

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions lib/idempo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def call(env)
end

status, headers, body = @app.call(env)
# `body` could be of type `ActionDispatch::Response::RackBody` and idempo will not even attempt to store it,
# we're converting ActionDispatch::Response::RackBody to a storable array format.
body = body.try(:to_ary) || body
julik marked this conversation as resolved.
Show resolved Hide resolved

expires_in_seconds = (headers.delete("X-Idempo-Persist-For-Seconds") || @persist_for_seconds).to_i
if response_may_be_persisted?(status, headers, body)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely you want to call to_ary here, actually - because an Array of strings may be persistable, and replacing body with the "materialized" array will allow response_may_be_persisted? to size it correctly by a sum of bytesizes of the array elements. So first call to_ary to materialize, then check for whether the materialized body is too big.

Expand Down