diff --git a/uvicorn/protocols/utils.py b/uvicorn/protocols/utils.py index c9347277d..93422e4bf 100644 --- a/uvicorn/protocols/utils.py +++ b/uvicorn/protocols/utils.py @@ -1,5 +1,10 @@ import socket +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") @@ -14,8 +19,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: @@ -28,7 +34,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")