-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quality arguments to Accept
header should default to 1.0
#2366
Conversation
Accept
header should default to 1.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test that with nil
, 0.0
, and invalid
, too?
Thanks for the review. I changed the parsing to include all |
Add to CHANGELOG and this is good to go! |
Thanks, done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more, should we also document this in README? We don't need to explain the entire purpose of q
, but maybe call it out in https://github.com/ruby-grape/grape#header with an example that chooses JSON over XML? Maybe something like this?
"Grape will evaluate the relative quality preference included in Accept headers and default to a quality of 1.0 when omitted. In the following example a Grape API that supports XML and JSON in that order will return JSON."
curl ... -H "Accept: text/xml;q=0.8, application/json;q=0.9"
Sounds good, done in 7a6cefc! |
Merged, nice work, thanks for hanging in here with me! |
This PR ensures that Accept headers with mime types without a given quality value, are parsed as having a quality value of
1.0
.The current value for mime types without a quality value is 0.0 (
nil.to_f
).From the HTTP specification (RFC 9110), https://www.rfc-editor.org/rfc/rfc9110.html#name-accept and https://www.rfc-editor.org/rfc/rfc9110.html#name-quality-values: