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 67b60b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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 67b60b4

Please sign in to comment.