Skip to content

Commit f5b4dfd

Browse files
committed
Support rack requests in Slack::Events::Request
The `#headers` method on a request is implemented by Rails, so in order for the event request class to support other rack based servers we can instead look for the headers via `#get_header` or `#env`. Since Rail's requests are an extension of rack requests this will also work in a Rails app.
1 parent 1158c92 commit f5b4dfd

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/slack/events/request.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ def initialize(http_request, options = {})
1919

2020
# Request timestamp.
2121
def timestamp
22-
@timestamp ||= http_request.headers['X-Slack-Request-Timestamp']
22+
@timestamp ||= http_request.get_header('HTTP_X_SLACK_REQUEST_TIMESTAMP')
2323
end
2424

2525
# The signature is created by combining the signing secret with the body of the request
2626
# Slack is sending using a standard HMAC-SHA256 keyed hash.
2727
def signature
28-
@signature ||= http_request.headers['X-Slack-Signature']
28+
@signature ||= http_request.get_header('HTTP_X_SLACK_SIGNATURE')
2929
end
3030

3131
# Signature version.

spec/slack/events/request_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
'"P7sFXA4o3HV2hTx4zb4zcQ9yrvuQs8pDh6EacOxmMRj0tJaXfQFF","type":"url_verification"}'
2222
end
2323
let(:http_request) do
24-
double(
25-
headers: {
26-
'X-Slack-Request-Timestamp' => timestamp,
27-
'X-Slack-Signature' => signature
28-
},
24+
request_double = double(
2925
body: StringIO.new(body)
3026
)
27+
28+
allow(request_double).to receive(:get_header).with('HTTP_X_SLACK_REQUEST_TIMESTAMP') { timestamp }
29+
allow(request_double).to receive(:get_header).with('HTTP_X_SLACK_SIGNATURE') { signature }
30+
31+
request_double
3132
end
3233

3334
after do

0 commit comments

Comments
 (0)