INNER CODE UNIT · Python
_parse_host_authority
ohdearquant/lionagi · lionagi/studio/app.py:250
def _parse_host_authority(raw_host: str) -> str | None:
"""Strictly parse a raw Host header value: normalized host (lowercased,
brackets stripped for IPv6), or None if it doesn't match the grammar."""
raw_host = (raw_host or "").strip()
if not raw_host:
return None
match = (
_IPV6_AUTHORITY_RE.match(raw_host)
if raw_host.startswith("[")
else _HOST_AUTHORITY_RE.match(raw_host)
)
if not match:
return None
host = match.group("host")
return host.lower() if host else None
async def validate_host_header(request: Request, call_next):