From ed6188b2c2a16b49e05cc11a3dc627a7ba05176c Mon Sep 17 00:00:00 2001 From: 40handz Date: Thu, 19 Mar 2026 10:55:57 -0400 Subject: [PATCH] Fix webhook content_type parsing for Rails 7.1+ Rails 7.1 changed ActionDispatch::Request#content_type to return the full Content-Type header value (e.g. "application/json; charset=utf-8") rather than just the MIME type. This caused webhook validation to raise "Unknown Content-Type" for any request with a charset parameter. Use request#media_type (available on ActionDispatch::Request) when present to extract only the MIME type, falling back to content_type for plain Rack::Request objects which are unaffected. Fixes #192 --- lib/pusher/webhook.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/pusher/webhook.rb b/lib/pusher/webhook.rb index cebbb54..f28782b 100644 --- a/lib/pusher/webhook.rb +++ b/lib/pusher/webhook.rb @@ -34,7 +34,10 @@ def initialize(request, client = Pusher) if request.respond_to?(:env) && request.respond_to?(:content_type) @key = request.env['HTTP_X_PUSHER_KEY'] @signature = request.env["HTTP_X_PUSHER_SIGNATURE"] - @content_type = request.content_type + # Rails 7.1+ changed content_type to return the full header value + # (e.g. "application/json; charset=utf-8"). Use media_type when + # available (ActionDispatch::Request) to get just the MIME type. + @content_type = request.respond_to?(:media_type) ? request.media_type : request.content_type request.body.rewind @body = request.body.read