forked from mtusi2026/mtusi2026lab4
Исправить замечания ревью: битый JPEG, память nginx, 502 вместо 413
JPEG проверяется через djpeg -strict: обрезанный поток с дописанным EOI теперь даёт 415. Память nginx больше не зависит от тел файлов: загрузка идёт потоком до API, скачивание без временных файлов, воркеров 2. API не закрывает соединение при недочитанном теле, что давало HTML 502; nginx сам отклоняет тела больше лимитов API. Лимит памяти API поднят до 512 MiB под проверку CMYK-JPEG на 40 Мпикс. Добавлен стресс-тест через LB.
This commit is contained in:
+2
-2
@@ -207,7 +207,7 @@ def non_blank(value: object, max_len: int) -> bool:
|
||||
async def read_json(request: Request, required: Tuple[str, ...], optional: Tuple[str, ...] = ()) -> dict:
|
||||
if request.headers.get("content-type", "").split(";")[0].strip().lower() != "application/json":
|
||||
raise ApiError(415, "unsupported_media_type", "Ожидается application/json")
|
||||
too_large = ApiError(413, "payload_too_large", "Тело запроса слишком большое", {"Connection": "close"})
|
||||
too_large = ApiError(413, "payload_too_large", "Тело запроса слишком большое")
|
||||
declared = request.headers.get("content-length")
|
||||
if declared and declared.isdigit() and int(declared) > config.MAX_BODY_BYTES:
|
||||
raise too_large
|
||||
@@ -527,7 +527,7 @@ async def upload_attachment(chat_id: str, request: Request):
|
||||
raise ApiError(415, "unsupported_media_type", "Допускается только image/png или image/jpeg")
|
||||
|
||||
declared_length = request.headers.get("content-length")
|
||||
too_large = ApiError(413, "payload_too_large", "Файл превышает 10 MiB", {"Connection": "close"})
|
||||
too_large = ApiError(413, "payload_too_large", "Файл превышает 10 MiB")
|
||||
if declared_length and declared_length.isdigit() and int(declared_length) > config.MAX_UPLOAD_BYTES:
|
||||
raise too_large
|
||||
ensure_capacity()
|
||||
|
||||
Reference in New Issue
Block a user