#5072·litestar

Bug: Accept.best_match() ignores q=0, returning media types the client explicitly marked unacceptable

Author: aviralsaxena16Created Sep 12, 2026Updated Sep 12, 2026
LabelsBug :bug:

Description

Media-range with q=0 in an Accept header isn't just low priority, it's explicitly marked unacceptable by the client.

MediaTypeHeader.priority parses q=0 into a quality of 0 correctly, but Accept.best_match() never actually checks this value before matching, it only checks maintype/subtype/param compatibility.

So in practice, best_match() (and accepts(), since it's built on the same logic) can end up returning a media type the client explicitly said it won't accept.

URL to code causing the issue

https://github.com/litestar-org/litestar/blob/main/litestar/datastructures/headers.py

MCVE

python
from litestar.datastructures import Accept

result = Accept("text/plain;q=0").best_match(["text/plain"])
assert result is None, f"expected None, got {result!r}"

Steps to reproduce

  1. Run the MCVE above
  2. Observe the assertion fails , best_match returns "text/plain" instead of None

Litestar Version

3.0.0b0