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

Rewind body after checking request signature #354

Merged

Conversation

sunny
Copy link
Contributor

@sunny sunny commented Dec 19, 2020

Before

Trying to read the request body after calling a Slack verification, returns an empty body:

Slack::Events::Request.new(request).verify!
request.body.read # => ""

This is because calling request.body.read on Rack requests causes the body’s StringIO to go to the end of the string.

After

Therefore, to minimize surprise, we can rewind the body after reading it. After this fix, we get the following:

Slack::Events::Request.new(request).verify!
request.body.read # => "payload=%7B%22type%22%3A%22blo…"

@dblock dblock merged commit 1523246 into slack-ruby:master Dec 21, 2020
@dblock
Copy link
Collaborator

dblock commented Dec 21, 2020

Thanks, makes sense!

@sunny sunny deleted the rewind-body-after-checking-request-signature branch December 22, 2020 09:30
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