Spaces:
Sleeping
Sleeping
Download app/services/client_ip.py from Rthur2003/crowncode-backend: direct link, hf CLI and curl.
- Browser
- Download file 586 Bytes
-
https://huggingface.co/spaces/Rthur2003/crowncode-backend/resolve/main/app/services/client_ip.py
- Command line
-
hf download hf://spaces/Rthur2003/crowncode-backend/app/services/client_ip.py
-
curl -L -o client_ip.py https://huggingface.co/spaces/Rthur2003/crowncode-backend/resolve/main/app/services/client_ip.py
586 Bytes
| """The visitor's address behind the Hugging Face proxy.""" | |
| from __future__ import annotations | |
| from fastapi import Request | |
| def client_ip(request: Request) -> str: | |
| """The address rate limits are counted against. | |
| uvicorn sees the proxy, so request.client alone would put every visitor in | |
| one bucket; the proxy lists the original client first in X-Forwarded-For. | |
| """ | |
| forwarded = request.headers.get("x-forwarded-for", "") | |
| first = forwarded.split(",")[0].strip() | |
| if first: | |
| return first | |
| return request.client.host if request.client else "unknown" | |