From 8b31678c6e44400967d4934cd9f3c6c6ac0da721 Mon Sep 17 00:00:00 2001 From: Max Nanis Date: Thu, 19 Feb 2026 20:11:41 -0500 Subject: Carer dir into project, some initial pytest, part of the flow tasks. License and Readme update --- jb/views/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 jb/views/utils.py (limited to 'jb/views/utils.py') diff --git a/jb/views/utils.py b/jb/views/utils.py new file mode 100644 index 0000000..39db5d2 --- /dev/null +++ b/jb/views/utils.py @@ -0,0 +1,15 @@ +from fastapi import Request + + +def get_client_ip(request: Request) -> str: + """ + Using a testclient, the ip returned is 'testclient'. If so, instead, grab + the ip from the headers + """ + ip = request.headers.get("X-Forwarded-For") + if not ip: + ip = request.client.host + elif ip == "testclient" or ip.startswith("10."): + forwarded = request.headers.get("X-Forwarded-For") + ip = forwarded.split(",")[0].strip() if forwarded else request.client.host + return ip -- cgit v1.2.3