#36447: HttpRequest.get_preferred_type misorders types when more specific
accepted
types have lower q
--------------------------------------+------------------------------------
Reporter: Anders Kaseorg | Owner: (none)
Type: Bug | Status: new
Component: HTTP handling | Version: 5.2
Severity: Normal | Resolution:
Keywords: preferred media type | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Jake Howard):
I've done some more digging, and I think the current implementation is
working as expected. Notably, there's this sentence in the RFC:
> Media ranges can be overridden by more specific media ranges or specific
media types. If more than one media range applies to a given type, the
most specific reference has precedence.
More specific definitions override less specific, even if the quality
value is higher. This was found and fixed as part of #36411.
The same example from the previous version of the RFC (7231) has a similar
example, which is copied verbatim into
[https://github.com/django/django/blob/main/tests/requests_tests/test_accept_header.py#L235-L262
Django's codebase]. If I plug the updated values into the same test case,
they pass ([https://www.rfc-editor.org/errata/eid7138 besides the final
case]). Notably, to find the specific entry in the `Accept` header which
matches the given type, the `.accepted_type` (internal) method should be
used, rather than `is_preferred_type` (which abstracts these
considerations away).
Unfortunately, these RFCs are quite hard to interpret. I've opened a
[https://forum.djangoproject.com/t/help-wanted-accept-header-
interpretation/41373 thread on the forum] to collect some more input.
--
Ticket URL: <https://code.djangoproject.com/ticket/36447#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019755bc9fb1-c3ff7618-530f-468a-913e-42a0808a4f08-000000%40eu-central-1.amazonses.com.