Hello!
2015-07-08 10:02 GMT+08:00 <
mike19...@gmail.com>:
> 谢谢大神的意见。
> 1.通过body_filter_by_lua
> 直接对响应体作修改,之前尝试过由于增加了chunk里面内容的字符内容,由于connect_length的影响,不能请求到全部内容。如果修改head的头信息的话(修改ngx.header.HEADER中相应的数值
> ),发现nginx的errorlog里面报
> 2015/07/08 07:23:43 [error] 27554#0: *260 attempt to set ngx.header.HEADER
> after sending out response headers while sending to client,
> 不知道对这种情况有什么解决办法吗?
你应该在 header_filter_by_lua 里面对响应头进行修改,在 body filter 里面改已经太晚了(上面的错误消息清楚地指示了这一点)。
> 2.body_filter_by_lua里面对chunk内容的修改是否不能增加或者删除内容,只能保证内容大小不变的情况下进行修改?
当然不是。引用一下 body_filter_by_lua 的官方文档对此问题的说明:
“When the Lua code may change the length of the response body, then it
is required to always clear out the Content-Length response header (if
any) in a header filter to enforce streaming output, as in
location /foo {
# fastcgi_pass/proxy_pass/...
header_filter_by_lua 'ngx.header.content_length = nil';
body_filter_by_lua 'ngx.arg[1] = string.len(ngx.arg[1]) .. "\\n"';
}
”
https://github.com/openresty/lua-nginx-module#body_filter_by_lua
引用一下官方文档:
“the "eof" flag indicating the end of the response body data stream is
passed via ngx.arg[2] (as a Lua boolean value)”
显然,ngx.arg[2] 就是 eof :)
Regards,
-agentzh