Handle empty/missing accept header more directly

This commit is contained in:
L. Karkkainen 2023-01-29 01:52:53 +00:00
parent e35286e332
commit 7909f673e5

View File

@ -178,8 +178,10 @@ def parse_accept(accept: str) -> AcceptList:
accorsing to RFC 7231, s. 5.3.2
https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2
"""
if not accept:
return AcceptList()
try:
a = [MediaType._parse(mtype) for mtype in accept.split(",") if mtype]
a = [MediaType._parse(mtype) for mtype in accept.split(",")]
return AcceptList(sorted(a, key=lambda mtype: -mtype.q))
except ValueError:
raise InvalidHeader(f"Invalid header value in Accept: {accept}")