From e08909eacda9efc20707edcd895eabb35be9b59d Mon Sep 17 00:00:00 2001 From: mxr612 Date: Mon, 16 Jun 2025 05:33:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0IP=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E9=80=BB=E8=BE=91=E4=BB=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改结果处理逻辑以获取真实IP地址,考虑代理头的影响 - 更新RawResponse模型中的ip_address字段以保存用户的真实IP --- app.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 05de73d..bf754f4 100644 --- a/app.py +++ b/app.py @@ -84,10 +84,14 @@ async def result(request: Request, scale_id: str, db: Session = Depends(get_db)) scale = scales.get(scale_id) if scale: # Save response to database + # Get real IP address considering proxy headers + ip = request.headers.get("X-Forwarded-For", "").split(",")[0].strip() or \ + request.headers.get("X-Real-IP", "") or \ + request.client.host db_response = RawResponse( scale_id=scale_id, user_agent=request.headers.get("user-agent", "Unknown"), - ip_address=request.client.host, + ip_address=ip, response=dict(form_data) ) db.add(db_response)