INNER CODE UNIT · Python
_split_content_type
redis/fastapi-redis-sdk · src/redis_fastapi/cache.py:304
def _split_content_type(raw: bytes | None) -> tuple[str, str | None]:
"""Split a ``Content-Type`` value into its media type and charset.
Both are lowercased. A missing header yields ``("", None)``, which no
allowlist entry matches, so an untyped response is refused rather than
guessed at.
Args:
raw: Raw ``Content-Type`` header value, or ``None``.
Returns:
A ``(media_type, charset)`` pair; *charset* is ``None`` when the
header declares none.
"""
if raw is None:
return "", None
media_type, _, params = raw.decode(HEADER_ENCODING).partition(";")
charset: str | None = None