Skip to content

Commit bcfc1d5

Browse files
authored
Merge pull request #198 from pusher/fix/rails-71-webhook-content-type
Fix webhook content_type parsing for Rails 7.1+
2 parents b5736cd + ed6188b commit bcfc1d5

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/pusher/webhook.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ def initialize(request, client = Pusher)
3434
if request.respond_to?(:env) && request.respond_to?(:content_type)
3535
@key = request.env['HTTP_X_PUSHER_KEY']
3636
@signature = request.env["HTTP_X_PUSHER_SIGNATURE"]
37-
@content_type = request.content_type
37+
# Rails 7.1+ changed content_type to return the full header value
38+
# (e.g. "application/json; charset=utf-8"). Use media_type when
39+
# available (ActionDispatch::Request) to get just the MIME type.
40+
@content_type = request.respond_to?(:media_type) ? request.media_type : request.content_type
3841

3942
request.body.rewind
4043
@body = request.body.read

0 commit comments

Comments
 (0)