Hello!
On Wed, Jul 17, 2013 at 2:53 PM, Viktor malezink <kro...@gmail.com> wrote:
> So ngx.arg[1] = string.len(ngx.arg[1] will return size of current chunk? Or
> size of full html?
The size of the current chunk, of course. You've already quoted the
documentation for ngx.arg[1] below yourself.
> And if
>>
>> Nginx output filters may be called multiple times for a single request
>> because response body may be delivered in chunks. Thus, the Lua code
>> specified by in this directive may also run multiple times in the lifetime
>> of a single HTTP request.
>
> Thats mean i can do something like that.
>
>> if ngx.arg[2] == false then
>>
>> ngx.ctx.current_html = ngx.ctx.current_html..ngx.arg[1]
>>
Don't do this, string concatenation is very expensive, even more
expensive than full response body buffering itself.
BTW, even when ngx.arg[2] is true, ngx.arg[1] could contain data. They
are not exclusive at all.
Also, it's always easy to test everything yourself by means of
ngx_echo which can easily emit multiple small data chunks. For
example,
echo hello;
echo world;
will emit 3 data chunks with the last one does not contain data but
the "eof" flag only. You can use this to test your body filters. FWIW,
I'm also using this ngx_echo module to test my ngx_replace_filter
module. Check out its test suite below:
https://github.com/agentzh/replace-filter-nginx-module/tree/master/t
Regards,
-agentzh