allow dashes, periods, and other RFC6838-compliant characters in header vendor #1170
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.
The current accept header parsing logic treats everything after the first
-
as the version, whereas it's not uncommon to have dashes in more complex vendor/resource media type definitions (an IANA-registered example isapplication/vnd.ms-office.activeX+xml
)This change correctly handles dashes in the vendor part, while still assuming what's after the last dash is the version.
The current logic also doesn't allow underscores, ampersands, etc, which are allowed media type characters per RFC 6838. This change makes Grape itself handle these characters correctly, however for them to actually work is contingent on mjackson/rack-accept#17 which unfortunately has been open for more than 6 months (I'll ping maintainer again, but any weight you can throw around there would also be appreciated 😄)
P/S: It should be noted that the current header versioning logic is very limited and doesn't support formats such as
application/vnd.github.v3+json
(as what github uses now) I'll try to add a caveat in the README while I add the CHANGELOG entry for this