-
Notifications
You must be signed in to change notification settings - Fork 281
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
Fix error with body.rewind with rack 3.0 #1107
Conversation
Thanks @aglushkov , we're taking a look at this. |
@aglushkov Thanks for bringing up this issue, and thank you for the PR. I looked up the rack issue (rack/rack#1148) and PR (rack/rack#1804) for more insight. My concern about this PR is that the input is still IO-like, and reading from it will still update the IO cursor. The difference is that since it is non-rewindable, it can only be read once, so rollbar-gem probably shouldn't be reading it. Am I missing something that would make this safe as is? |
@waltjones Your concerns are correct.
There are Rack::RewindableInput class in Rack-2 I would suggest using not-public def rewind_body(rack_req)
body = rack_req.body
if body.respond_to?(:rewind)
body.rewind
else
# workaround for Rack 3.0
# for my application (Rack, Roda, Puma) `body_input` is StringIO, Puma::NullIO, Tempfile, everything is rewindable
body_input = body.instance_variable_get(:@input)
body_input.rewind if body_input.respond_to?(:rewind) # additional check if its not rewindable
end
end Such should be used before and after reading input. |
@aglushkov Nice workaround! I have two suggestions.
return {} unless rewindable?(rack_req) |
It turns out this |
@aglushkov That sounds fine. We still need to skip rack_req.body.read if the input is not rewindable. |
#1106 In rack 3.0 there are no method `#rewind` in Rack::Lint::InputWrapper that existed in rack 2.2
@waltjones Sorry for delay, I've update PR, add test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aglushkov Nice work. Thank you for the test coverage, and thank you again for the PR.
In rack 3.0 there are no method
#rewind
in Rack::Lint::InputWrapper that existed in rack 2.2Type of change
Related issues