Spaces:
Runtime error
Runtime error
Claude commited on
fix: get_client_ip 헤더 탐색 범위 확장 + 미발견 시 헤더 목록 로그
Browse files대소문자 변형 헤더(X-Forwarded-For 등) 추가 탐색.
IP를 찾지 못한 경우 수신된 헤더 키 목록을 로그로 출력하여
배포 환경별 헤더 이름 디버깅 가능하도록 개선.
https://claude.ai/code/session_016DE3uHLsVmA5Uv7gZGGaKT
utils.py
CHANGED
|
@@ -60,10 +60,18 @@ def get_client_ip():
|
|
| 60 |
return ""
|
| 61 |
if not headers:
|
| 62 |
return ""
|
| 63 |
-
for key in ["x-forwarded-for", "x-real-ip", "cf-connecting-ip", "fly-client-ip"
|
|
|
|
|
|
|
| 64 |
raw_ip = headers.get(key)
|
| 65 |
if raw_ip:
|
| 66 |
return str(raw_ip).split(",")[0].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
return ""
|
| 68 |
|
| 69 |
|
|
|
|
| 60 |
return ""
|
| 61 |
if not headers:
|
| 62 |
return ""
|
| 63 |
+
for key in ["x-forwarded-for", "x-real-ip", "cf-connecting-ip", "fly-client-ip",
|
| 64 |
+
"X-Forwarded-For", "X-Real-Ip", "CF-Connecting-IP", "True-Client-Ip",
|
| 65 |
+
"true-client-ip"]:
|
| 66 |
raw_ip = headers.get(key)
|
| 67 |
if raw_ip:
|
| 68 |
return str(raw_ip).split(",")[0].strip()
|
| 69 |
+
# 헤더에서 IP를 찾지 못한 경우 사용 가능한 헤더 목록을 로그로 남김
|
| 70 |
+
try:
|
| 71 |
+
all_keys = list(headers.keys()) if headers else []
|
| 72 |
+
logger.info("get_client_ip: IP 헤더 없음. 수신된 헤더 키: %s", all_keys)
|
| 73 |
+
except Exception:
|
| 74 |
+
pass
|
| 75 |
return ""
|
| 76 |
|
| 77 |
|