Use client IP (potentially proxied) in logs, handle [ipv6].

This commit is contained in:
Leo Vasanko
2026-04-24 20:13:11 +00:00
parent 522dd49f3f
commit 3e337bf1f2
2 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ async def log_access(req, res):
return res
start = getattr(req.ctx, "_log_start", None)
duration_ms = (time.perf_counter() - start) * 1000 if start is not None else 0.0
client = req.ip or "-"
client = req.client_ip or "-"
host = req.host or "-"
path = req.path
if req.query_string:
+3 -3
View File
@@ -55,8 +55,8 @@ def format_client_ip(ip: str) -> str:
return "-"
stripped = ip.strip("[]")
if ":" in stripped:
return format_ipv6_network(ip)
return ip
return format_ipv6_network(stripped)
return stripped
def status_color(status: int) -> str:
@@ -144,7 +144,7 @@ def log_ws_open(request, extra: str | None = None) -> int:
"""Log WebSocket connection open. Returns connection ID for use in log_ws_close."""
ws_id = _next_ws_id()
client = request.ip or "-"
client = request.client_ip or "-"
host = request.host or "-"
path = request.path
origin = request.headers.get("origin")