Hi, I get an issue: I need to get the response of a proxy_pass, and write it into a log. Is there any way to get this done ? Thanks. .
Hello,You can take a look in body_filter_by_lua.Something like this:body_filter_by_lua ' ngx.log(ngx.ERR,ngx.arg[1])';Be careful and check the response's Content-Type.Regards,Guilherme On Tue, Jan 5, 2016 at 1:34 AM, hao dong <hao....@gmail.com> wrote:Hi, I get an issue: I need to get the response of a proxy_pass, and write it into a log. Is there any way to get this done ? Thanks. .
Hello,You can take a look in body_filter_by_lua.Something like this:body_filter_by_lua ' ngx.log(ngx.ERR,ngx.arg[1])';Be careful and check the response's Content-Type.Regards,Guilherme On Tue, Jan 5, 2016 at 1:34 AM, hao dong <hao.a...@gmail.com> wrote:Hi, I get an issue: I need to get the response of a proxy_pass, and write it into a log. Is there any way to get this done ? Thanks. .
Hello,I just wanted to expand on Guiherme's reply a bit. Be sure to understand that ngx.arg[1] is a buffered or chunked response and is not likely contain the entire upstream response. Because of this, your body_filter will actually be called multiple times. You must dynamically 'build up' an output buffer by storing previous concatenated chunks in ngx.ctx (or similar). I've posted a gist file example to demonstrate this at https://gist.github.com/lordnynex/ada41f7d17c68aa62961More information and examples can be found in the body_filter_* documentation at https://github.com/openresty/lua-nginx-module#body_filter_by_luaPlease be sure to use the new *_by_lua_block style syntax for newer versions of Openresty. -Brandon On Tue, Jan 5, 2016 at 5:30 AM, Guilherme <guilh...@gmail.com> wrote:Hello,You can take a look in body_filter_by_lua.Something like this:body_filter_by_lua ' ngx.log(ngx.ERR,ngx.arg[1])';Be careful and check the response's Content-Type.Regards,Guilherme On Tue, Jan 5, 2016 at 1:34 AM, hao dong <hao.a...@gmail.com> wrote:Hi, I get an issue: I need to get the response of a proxy_pass, and write it into a log. Is there any way to get this done ? Thanks. .