Include quality value when parsing Accept header
Requests have an accepts
method for identifying the mimetype the user can receive. However, when multiple formats are provided, a quality value can be added to show the preferences on format. Handling this value currently needs to be done by hand.
I propose:
- Documenting the existence of
Request.accepted_types
- Extract the quality value, and store it as
MediaType.quality
- Sort
Request.accepted_types
by quality value
It would be nice to have an API to answer "I can return these mime types, which would you prefer?", which I guess could be handled manually for now.
Change History
(12)
Triage Stage: |
Unreviewed → Accepted
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
I think step 3 should read "Sort Request.accepted_types by quality value and specificity", e.g.
text/*;q=0.8,text/html;q=0.8
should be sortedtext/html
first.This is probably a sensible proposal. I suspect most people are not sending the quality value, so
1
is assumed and it has no effect. Nonetheless why not allow it?We'd need a new helper API on HttpRequest taking a set of mime types to match against, since the specificity question (
text/*
) makes it slightly more complex than just returning the first match in accepted_types from the set.DRF has implementations of this logic that can be used for reference: