diff options
| author | Max Nanis | 2026-02-19 20:11:41 -0500 |
|---|---|---|
| committer | Max Nanis | 2026-02-19 20:11:41 -0500 |
| commit | 8b31678c6e44400967d4934cd9f3c6c6ac0da721 (patch) | |
| tree | 41c5f4479c353a16da1a8b6fa9088abd084ea388 /jb/views/utils.py | |
| parent | f0f96f83c2630e890a2cbcab53f77fd4c37e1684 (diff) | |
| download | amt-jb-8b31678c6e44400967d4934cd9f3c6c6ac0da721.tar.gz amt-jb-8b31678c6e44400967d4934cd9f3c6c6ac0da721.zip | |
Carer dir into project, some initial pytest, part of the flow tasks. License and Readme update
Diffstat (limited to 'jb/views/utils.py')
| -rw-r--r-- | jb/views/utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
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 |
