嗨,
ngx.req.set_body_file和ngx.req.set_body_data的文档描述如下:
If the current request's request body has not been read, then it will be properly discarded.
实测代码如下:
server {
location / {
rewrite_by_lua_block {
ngx.req.set_body_data("helloworld")
}
}
}
error.log报错:
2018/01/12 14:02:39 [error] 82355#2570778: *1 lua entry thread aborted: runtime error: content_by_lua(ngx.req.set_body_file.conf:20):3: request body not read yet
stack traceback:
coroutine 0:
[C]: in function 'set_body_file'
content_by_lua(ngx.req.set_body_file.conf:20):3: in function <content_by_lua(ngx.req.set_body_file.conf:20):1>, client: 127.0.0.1, server: , request: "POST / HTTP/1.1", host: "127.0.0.1:8000"
貌似调用set_body_file或set_body_data前,必须手动调用ngx.req.read_body才可以。
问题是:根据文档描述,手动调用ngx.req.read_body是不是可以不用做呀?