Skip to content

Fix webhook content_type parsing for Rails 7.1+#198

Open
Keith-wright wants to merge 1 commit intomasterfrom
fix/rails-71-webhook-content-type
Open

Fix webhook content_type parsing for Rails 7.1+#198
Keith-wright wants to merge 1 commit intomasterfrom
fix/rails-71-webhook-content-type

Conversation

@Keith-wright
Copy link
Contributor

@Keith-wright Keith-wright commented Mar 19, 2026

Problem

Rails 7.1 changed ActionDispatch::Request#content_type to return the full Content-Type header value (e.g. application/json; charset=utf-8) instead of just the MIME type. This causes WebHook#data to raise "Unknown Content-Type (application/json; charset=utf-8)" for any request that includes a charset parameter.

Fixes #192

Solution

Use request.media_type when available (ActionDispatch::Request responds to it and always returns just the MIME type), falling back to request.content_type for plain Rack::Request objects, which are unaffected by the Rails 7.1 change.

@content_type = request.respond_to?(:media_type) ? request.media_type : request.content_type

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
@Keith-wright Keith-wright force-pushed the fix/rails-71-webhook-content-type branch from f4c0ac9 to ed6188b Compare March 19, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rails 7.1 will return Content-Type header without modification. If you want just the MIME type, please use #media_type instead.

2 participants