Formatting from header acts like Versioning from header #2548
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.
This PR changes the how the content_type is negotiated in
Grape::Middleware::Formatter
when looking in the ACCEPT header. Since #2389,Grape::Middleware::Versioner::Header
is usingRack::Utils.best_q_match
to find it but notGrape::Middleware::Formatter
. It seems totally legit that both should act the same way.This PR also optimize the negotiation regarding the extension found in a path lie
/api/v2/test.json
. Originally, it was usingsplit
without limit the number of occurrences that could be found and since its always looking at the end of string , it felts natural to just find the first dot starting from the end of the string.Finally,
Grape::Middleware::Formatter
won't approximate the content-type. This test was expecting an approximation when using a vendor/type formIMO, it didn't make sense since user should use versioning through
Grape::Middleware::Versioner
in their API. It was made for this.