diff --git a/uvicorn/protocols/utils.py b/uvicorn/protocols/utils.py index a282c61eb..b5cd72b50 100644 --- a/uvicorn/protocols/utils.py +++ b/uvicorn/protocols/utils.py @@ -1,6 +1,11 @@ import socket import urllib +if hasattr(socket, "AF_UNIX"): + SUPPORTED_SOCKET_FAMILIES = (socket.AF_INET, socket.AF_INET6, socket.AF_UNIX) +else: + SUPPORTED_SOCKET_FAMILIES = (socket.AF_INET, socket.AF_INET6) + def get_remote_addr(transport): socket_info = transport.get_extra_info("socket") @@ -15,8 +20,9 @@ def get_remote_addr(transport): else: family = socket_info.family - if family in (socket.AF_INET, socket.AF_INET6): + if family in SUPPORTED_SOCKET_FAMILIES: return (str(info[0]), int(info[1])) + return None info = transport.get_extra_info("peername") if info is not None and isinstance(info, (list, tuple)) and len(info) == 2: @@ -29,7 +35,7 @@ def get_local_addr(transport): if socket_info is not None: info = socket_info.getsockname() family = socket_info.family - if family in (socket.AF_INET, socket.AF_INET6): + if family in SUPPORTED_SOCKET_FAMILIES: return (str(info[0]), int(info[1])) return None info = transport.get_extra_info("sockname")