diff --git a/httpx/_utils.py b/httpx/_utils.py index 7fe827da4d..1093872dce 100644 --- a/httpx/_utils.py +++ b/httpx/_utils.py @@ -227,6 +227,10 @@ def __eq__(self, other: typing.Any) -> bool: def is_ipv4_hostname(hostname: str) -> bool: + """ + Check if the given hostname is a valid IPv4 address. + Supports CIDR notation by checking only the address part. + """ try: ipaddress.IPv4Address(hostname.split("/")[0]) except Exception: @@ -235,6 +239,10 @@ def is_ipv4_hostname(hostname: str) -> bool: def is_ipv6_hostname(hostname: str) -> bool: + """ + Check if the given hostname is a valid IPv6 address. + Supports CIDR notation by checking only the address part. + """ try: ipaddress.IPv6Address(hostname.split("/")[0]) except Exception: