上传文件大小怎么限制?超限时服务器读了多少?限制什么时候检查?chunked 上传也受限吗?这篇既用 test client 也用真实的 30 MB 上传来验证。
默认配置: {'MAX_CONTENT_LENGTH': None, 'request.max_content_length': None}
设成 1000 后: {'MAX_CONTENT_LENGTH': 1000, 'request.max_content_length': 1000}
POST /raw 正文 500 字节 → 200 {"len":500}
POST /raw 正文 1000 字节 → 200 {"len":1000}
POST /raw 正文 1001 字节 → 413 <!doctype html> <html lang=en> <title>413 Request Entity Too Large</ti
POST /raw 正文 100000 字节 → 413 <!doctype html> <html lang=en> <title>413 Request Entity Too Large</ti上一篇:多文件上传;下一篇:secure_filename() 的安全处理。
视图完全不读请求体,发 100000 字节(超限)→ 200
multipart 上传 5000 字节的文件 → 413 {'code': 413, 'error': 'RequestEntityTooLarge'} 全局不限制,视图里设 request.max_content_length = 100,发 500 字节 → 413
发 50 字节 → 200 {'len': 50}500 KB(限制内) → 200 上传 512213 字节 0.003929s 30 MB(超限) → 413 上传 720896 字节 0.001143s 30 MB,视图不读请求体 → 200 上传 393216 字节 0.000960s 30 MB chunked(无 CL) → 200 上传 1791044 字节 0.002573s | 响应正文:'1048576'
自定义 413 处理器: 413 {'error': 'payload too large', 'limit': 10}
默认 413 页: 413 <!doctype html> <html lang=en> <title>413 Request Entity Too Large</title> <h1>Request Entity Too Large</h1> <