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

Added new client_ip accessor #2114

Merged
merged 9 commits into from Jun 16, 2021
2 changes: 1 addition & 1 deletion sanic/request.py
Expand Up @@ -505,7 +505,7 @@ def ip(self) -> str:
:return: peer ip of the socket
:rtype: str
"""
return self.conn_info.client if self.conn_info else ""
return self.conn_info.client_ip if self.conn_info else ""

@property
def port(self) -> int:
Expand Down
3 changes: 3 additions & 0 deletions sanic/server.py
Expand Up @@ -65,6 +65,7 @@ class ConnInfo:
__slots__ = (
"client_port",
"client",
"client_ip",
"ctx",
"peername",
"server_port",
Expand All @@ -78,6 +79,7 @@ def __init__(self, transport: TransportProtocol, unix=None):
self.peername = None
self.server = self.client = ""
self.server_port = self.client_port = 0
self.client_ip = ""
self.sockname = addr = transport.get_extra_info("sockname")
self.ssl: bool = bool(transport.get_extra_info("sslcontext"))

Expand All @@ -96,6 +98,7 @@ def __init__(self, transport: TransportProtocol, unix=None):

if isinstance(addr, tuple):
self.client = addr[0] if len(addr) == 2 else f"[{addr[0]}]"
self.client_ip = addr[0]
self.client_port = addr[1]


Expand Down