From e94520a3fd9edad8edccfcdb1689ba89238a2a4e Mon Sep 17 00:00:00 2001 From: kebyn Date: Mon, 2 Sep 2024 02:10:41 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=9D=9E=E6=A0=87?= =?UTF-8?q?=E5=87=86=E5=AE=9E=E7=8E=B0=20X-Forwarded-For=20=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/utils/common.py | 4 ++-- apps/common/utils/http.py | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/apps/common/utils/common.py b/apps/common/utils/common.py index b2c695c74..4715906df 100644 --- a/apps/common/utils/common.py +++ b/apps/common/utils/common.py @@ -158,7 +158,7 @@ def is_uuid(seq): def get_request_ip(request): x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR', '').split(',') if x_forwarded_for and x_forwarded_for[0]: - login_ip = x_forwarded_for[0] + login_ip = x_forwarded_for[0].split(":")[0] return login_ip login_ip = request.META.get('REMOTE_ADDR', '') @@ -293,7 +293,7 @@ def get_docker_mem_usage_if_limit(): inactive_file = int(inactive_file) return ((usage_in_bytes - inactive_file) / limit_in_bytes) * 100 - except Exception as e: + except Exception: return None diff --git a/apps/common/utils/http.py b/apps/common/utils/http.py index baf741407..30baa8d01 100644 --- a/apps/common/utils/http.py +++ b/apps/common/utils/http.py @@ -39,10 +39,6 @@ def iso8601_to_unixtime(time_string): return to_unixtime(time_string, _ISO8601_FORMAT) -def get_remote_addr(request): - return request.META.get("HTTP_X_FORWARDED_HOST") or request.META.get("REMOTE_ADDR") - - def is_true(value): return value in BooleanField.TRUE_VALUES