From 3af6e0f97e01794ba5b16365712f01557dd46e01 Mon Sep 17 00:00:00 2001 From: zhangtao <9480807882@qq.com> Date: Fri, 5 Sep 2025 02:22:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(router):=20=E4=BC=98=E5=8C=96=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=8F=82=E6=95=B0=E6=97=A5=E5=BF=97=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将表单请求参数格式化为字符串,避免日志记录对象格式 - 修正请求参数长度判断,避免超长参数存储 - 统一使用字符串格式的请求参数记录日志 - 保持对非表单请求的处理逻辑不变 --- backend/app/core/router_class.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/app/core/router_class.py b/backend/app/core/router_class.py index 834ee635..982d7243 100644 --- a/backend/app/core/router_class.py +++ b/backend/app/core/router_class.py @@ -46,8 +46,9 @@ class OperationLogRoute(APIRoute): if req_content_type and ( req_content_type.startswith('multipart/form-data') or req_content_type.startswith('application/x-www-form-urlencoded') ): - payload = await request.form() - oper_param = '\n'.join([f'{k}: {v}' for k, v in payload.items()]) + form_data = await request.form() + oper_param = '\n'.join([f'{k}: {v}' for k, v in form_data.items()]) + payload = oper_param # 直接使用字符串格式的参数 else: payload = await request.body() path_params = request.path_params @@ -60,8 +61,8 @@ class OperationLogRoute(APIRoute): # payload = str(oper_param) # 日志表请求参数字段长度最大为2000,因此在此处判断长度 - if len(oper_param) > 2000: - oper_param = '请求参数过长' + if len(payload) > 2000: + payload = '请求参数过长' response_data = response.body if "application/json" in response.headers.get("Content-Type", "") else b"{}" process_time = f"{(time.time() - start_time):.4f}s"