fix: 修复大请求体导致的 Empty body 错误
问题: - 当请求体超过 Nginx 缓冲区大小(默认较小)时 - ngx.req.get_body_data() 返回 nil - Nginx 会将请求体写入临时文件 解决: - 检查 ngx.req.get_body_file() 获取临时文件路径 - 从临时文件读取完整请求体 - 支持任意大小的请求体(通义听悟 ~100KB) 影响: - 修复通义听悟等数据量较大的网站同步失败问题
This commit is contained in:
@@ -139,6 +139,18 @@ http {
|
|||||||
ngx.req.read_body()
|
ngx.req.read_body()
|
||||||
local body = ngx.req.get_body_data()
|
local body = ngx.req.get_body_data()
|
||||||
|
|
||||||
|
-- 如果 body 为空,可能是因为请求体被写入了临时文件
|
||||||
|
if not body then
|
||||||
|
local body_file = ngx.req.get_body_file()
|
||||||
|
if body_file then
|
||||||
|
local file = io.open(body_file, "r")
|
||||||
|
if file then
|
||||||
|
body = file:read("*all")
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if not body then
|
if not body then
|
||||||
ngx.status = 400
|
ngx.status = 400
|
||||||
ngx.say(cjson.encode({error = "Empty body"}))
|
ngx.say(cjson.encode({error = "Empty body"}))
|
||||||
|
|||||||
Reference in New Issue
Block a user