Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected --proxy-headers client ip/host when using a unix socket #636

Merged
merged 11 commits into from Jul 28, 2020
17 changes: 13 additions & 4 deletions uvicorn/protocols/utils.py
@@ -1,4 +1,5 @@
import socket
import sys


def get_remote_addr(transport):
Expand All @@ -14,8 +15,12 @@ def get_remote_addr(transport):
else:
family = socket_info.family

if family in (socket.AF_INET, socket.AF_INET6):
return (str(info[0]), int(info[1]))
if not sys.platform.startswith("win"):
rafalp marked this conversation as resolved.
Show resolved Hide resolved
if family in (socket.AF_INET, socket.AF_INET6, socket.AF_UNIX):
euri10 marked this conversation as resolved.
Show resolved Hide resolved
return (str(info[0]), int(info[1]))
else:
if family in (socket.AF_INET, socket.AF_INET6):
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:
Expand All @@ -28,8 +33,12 @@ 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):
return (str(info[0]), int(info[1]))
if not sys.platform.startswith("win"):
if family in (socket.AF_INET, socket.AF_INET6, socket.AF_UNIX):
return (str(info[0]), int(info[1]))
else:
if family in (socket.AF_INET, socket.AF_INET6):
return (str(info[0]), int(info[1]))
return None
info = transport.get_extra_info("sockname")
if info is not None and isinstance(info, (list, tuple)) and len(info) == 2:
Expand Down