Skip to content

Commit dabb9e5

Browse files
committed
Fix: rewind body before reading it.
1 parent 015f615 commit dabb9e5

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### 2.2.1 (Next)
22

33
* [#494](https://github.com/slack-ruby/slack-ruby-client/pull/494): Configure Dependabot to update GitHub Actions - [@olleolleolle](https://github.com/olleolleolle).
4+
* [#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).
45
* [#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).
56
* Your contribution here.
67

lib/slack/events/request.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ def version
3838
# Request body.
3939
def body
4040
@body ||= begin
41-
body = http_request.body.read
42-
http_request.body.rewind
41+
input = http_request.body
42+
input.rewind
43+
body = input.read
44+
input.rewind
4345
body
4446
end
4547
end

spec/slack/events/request_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@
4747
expect(http_request.body.read).to eq body
4848
end
4949

50+
context 'with an already read body' do
51+
before do
52+
http_request.body.read
53+
end
54+
55+
it 'rewinds the request body before reading it' do
56+
expect(request.body).to eq body
57+
expect(http_request.body.read).to eq body
58+
end
59+
end
60+
5061
context 'time' do
5162
after do
5263
Timecop.return

0 commit comments

Comments
 (0)