Use client IP (potentially proxied) in logs, handle [ipv6].
This commit is contained in:
+1
-1
@@ -94,7 +94,7 @@ async def log_access(req, res):
|
|||||||
return res
|
return res
|
||||||
start = getattr(req.ctx, "_log_start", None)
|
start = getattr(req.ctx, "_log_start", None)
|
||||||
duration_ms = (time.perf_counter() - start) * 1000 if start is not None else 0.0
|
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 "-"
|
host = req.host or "-"
|
||||||
path = req.path
|
path = req.path
|
||||||
if req.query_string:
|
if req.query_string:
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ def format_client_ip(ip: str) -> str:
|
|||||||
return "-"
|
return "-"
|
||||||
stripped = ip.strip("[]")
|
stripped = ip.strip("[]")
|
||||||
if ":" in stripped:
|
if ":" in stripped:
|
||||||
return format_ipv6_network(ip)
|
return format_ipv6_network(stripped)
|
||||||
return ip
|
return stripped
|
||||||
|
|
||||||
|
|
||||||
def status_color(status: int) -> str:
|
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."""
|
"""Log WebSocket connection open. Returns connection ID for use in log_ws_close."""
|
||||||
ws_id = _next_ws_id()
|
ws_id = _next_ws_id()
|
||||||
|
|
||||||
client = request.ip or "-"
|
client = request.client_ip or "-"
|
||||||
host = request.host or "-"
|
host = request.host or "-"
|
||||||
path = request.path
|
path = request.path
|
||||||
origin = request.headers.get("origin")
|
origin = request.headers.get("origin")
|
||||||
|
|||||||
Reference in New Issue
Block a user