Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions httpx/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down