Handle empty/missing accept header more directly
This commit is contained in:
parent
e35286e332
commit
7909f673e5
@ -178,8 +178,10 @@ def parse_accept(accept: str) -> AcceptList:
|
|||||||
accorsing to RFC 7231, s. 5.3.2
|
accorsing to RFC 7231, s. 5.3.2
|
||||||
https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2
|
https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2
|
||||||
"""
|
"""
|
||||||
|
if not accept:
|
||||||
|
return AcceptList()
|
||||||
try:
|
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))
|
return AcceptList(sorted(a, key=lambda mtype: -mtype.q))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise InvalidHeader(f"Invalid header value in Accept: {accept}")
|
raise InvalidHeader(f"Invalid header value in Accept: {accept}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user