Skip to content

Commit

Permalink
Corrected --proxy-headers client ip/host when using a unix socket (#636)
Browse files Browse the repository at this point in the history
* Added AF_UNIX type socket to get client filled

* Removed travis debug

* Added travis verbose pytest for windows fail check

* Added travis verbose pytest for windows fail check

* No more tests output in travis now it's fixed on windows

* Useing a top level constant

* Lint
  • Loading branch information
euri10 authored Jul 28, 2020
1 parent 895807f commit a796e1d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions uvicorn/protocols/utils.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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:
Expand All @@ -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")
Expand Down

0 comments on commit a796e1d

Please sign in to comment.