From 33bfdf1928cf059f1e41515944045bab400ab06b Mon Sep 17 00:00:00 2001 From: helloplhm-qwq Date: Sat, 8 Jun 2024 11:50:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8Dgcsp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/gcsp.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/common/gcsp.py b/common/gcsp.py index d8ccde7..ff08449 100644 --- a/common/gcsp.py +++ b/common/gcsp.py @@ -14,7 +14,7 @@ import ujson as json import modules from .utils import createMD5 as hashMd5 from . import config -from aiohttp.web import Response +from aiohttp.web import Response, Request PACKAGE = config.read_config("module.gcsp.package_md5") # pkg md5 SALT_1 = config.read_config("module.gcsp.salt_1") # salt 1 @@ -72,9 +72,15 @@ async def handleGcspBody(body): else: return zlib.compress(json.dumps({"code": "403", "error_msg": "内部系统错误,请稍后再试", "data": None}, ensure_ascii = False).encode("utf-8")), 200 -async def handle_request(request): +async def handle_request(request: Request): if (request.method == "POST"): - body = await request.body() + content_size = request.content_length + if (content_size > 5 * 1024): # 5kb + return Response( + body = "Request Entity Too Large", + status = 413 + ) + body = await request.read() return Response( body = await handleGcspBody(body), content_type = "application/octet-stream"