Skip to content

Commit

Permalink
Fix: rewind body before reading it.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Jan 31, 2024
1 parent 015f615 commit dabb9e5
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 dabb9e5

Please sign in to comment.