Hello!
2014-09-18 2:39 GMT-07:00 顾昕:
> lua_need_request_body on;
> location /test {
> # echo $request_body;
> # content_by_lua "ngx.say(ngx.var.request_body)";
> }
> 上面一条命令显示为空,下面可以正常打印出request body,这是什么原因呢?
>
https://github.com/openresty/echo-nginx-module#echo_read_request_body
"Explicitly reads request body so that the $request_body variable will
always have non-empty values (unless the body is so big that it has
been saved by Nginx to a local temporary file)."
一般地,nginx 核心并不会主动读取请求体,而依赖各个 nginx 模块自己读取(包括 ngx_proxy, ngx_fastcgi,
ngx_lua, 和 ngx_echo)。而 ngx_lua 和 ngx_echo 都让用户决定是否读取(以及何时读取),前者通过
lua_need_request_body 指令或者 ngx.req.read_body() 或者 ngx.req.socket() 等
Lua API,而后者通过 echo_read_request_body 指令。
Regards,
-agentzh