Skip to content

Commit

Permalink
Merge pull request #508 from dblock/rack-3.0-rewind
Browse files Browse the repository at this point in the history
Fix: rewind body before reading it.
  • Loading branch information
dblock authored Jan 31, 2024
2 parents 015f615 + dabb9e5 commit fac7a6a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 2.2.1 (Next)

* [#494](https://github.com/slack-ruby/slack-ruby-client/pull/494): Configure Dependabot to update GitHub Actions - [@olleolleolle](https://github.com/olleolleolle).
* [#508](https://github.com/slack-ruby/slack-ruby-client/pull/508): Fix `Slack::Events::Request#verify!` compatibility with Rack 3.x - [@dblock](https://github.com/dblock).
* [#503](https://github.com/slack-ruby/slack-ruby-client/pull/503): Update Slack API Update API from [slack-api-ref@bc545649](https://github.com/slack-ruby/slack-api-ref/commit/bc545649) - [@dblock](https://github.com/dblock).
* Your contribution here.

Expand Down
6 changes: 4 additions & 2 deletions lib/slack/events/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ def version
# Request body.
def body
@body ||= begin
body = http_request.body.read
http_request.body.rewind
input = http_request.body
input.rewind
body = input.read
input.rewind
body
end
end
Expand Down
11 changes: 11 additions & 0 deletions spec/slack/events/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@
expect(http_request.body.read).to eq body
end

context 'with an already read body' do
before do
http_request.body.read
end

it 'rewinds the request body before reading it' do
expect(request.body).to eq body
expect(http_request.body.read).to eq body
end
end

context 'time' do
after do
Timecop.return
Expand Down

0 comments on commit fac7a6a

Please sign in to comment.