Hello,
Thanks for quick reply.
I am using ngx.location.capture inside "for loop" to concatenate output of two URIs.
for k,v in pairs(val) do
res = ngx.location.capture(v)
if (res.status == 200) then
ngx.print(res.body.."\n")
end
end
As you told ngx.location.capture buffers complete response then it would be more memory consuming I think. So can you suggest some better option for this case? I would like to process chunks with replace_filter (without buffering complete response).
Also can it be possible to run replace_filter wherever it is needed either before or after lua-nginx-module ? Because if I run replace_filter after "for loop" in above example, it will be applied to whole response body instead I need to execute it for some specific subrequest (location specific) when concatenating output of two URIs.
In below example, call to /xyz will call both locations /other1 and /other2. In /other1 replace_filter is called *after* lua-nginx-module. And call to /xyz requires to execute replace_filter (in /other1 location) *before* lua-nginx-module (in /xyz location).
location = /xyz {
content_by_lua '
.....
for k,v in pairs(val) do
res = ngx.location.capture(v)
if (res.status == 200) then
ngx.print(res.body.."\n")
end
end
.....
'
}
location /other1 {
body_filter_by_lua_file 'file.lua';
replace_filter 'PATTERN' '' g;
}
location /other2 {
body_filter_by_lua_file 'file.lua';
}
Regards,
Bhargav
On Saturday, November 30, 2013 3:04:29 AM UTC+5:30, agentzh wrote:
Hello!
On Fri, Nov 29, 2013 at 10:18 AM, <bha...@aum.bz> wrote:
> location = /xyz {
> content_by_lua '
> res = ngx.location.capture("/other");
> ngx.print(res.body)';
> }
>
> location /other {
> body_filter_by_lua_file 'file.lua';
> replace_filter 'PATTERN' '' g;
> }
>
Don't use replace_filter in the subrequest because there will be no
real gain here because ngx.location.capture will buffer the whole
request body anyway.
You can do the regex substitutions upon the subrequest's response body
by using the ngx.re.gsub or string.gsub API functions in your Lua code
directly:
https://github.com/chaoslawful/lua-nginx-module#ngxregsub
http://www.lua.org/manual/5.1/manual.html#pdf-string.gsub
Best regards,
-agentzh