Fix webhook content_type parsing for Rails 7.1+#198
Open
Keith-wright wants to merge 1 commit intomasterfrom
Open
Fix webhook content_type parsing for Rails 7.1+#198Keith-wright wants to merge 1 commit intomasterfrom
Keith-wright wants to merge 1 commit intomasterfrom
Conversation
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
f4c0ac9 to
ed6188b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Rails 7.1 changed
ActionDispatch::Request#content_typeto return the fullContent-Typeheader value (e.g.application/json; charset=utf-8) instead of just the MIME type. This causesWebHook#datato raise"Unknown Content-Type (application/json; charset=utf-8)"for any request that includes a charset parameter.Fixes #192
Solution
Use
request.media_typewhen available (ActionDispatch::Request responds to it and always returns just the MIME type), falling back torequest.content_typefor plainRack::Requestobjects, which are unaffected by the Rails 7.1 change.