Hello,
thank you for your response.
over the past few days, I am thinking about invoking the replace filter to Lua i.e. in the body filter code, I would write something like replace_filter_by_lua (arguments). This will enable use of Lua’s conditional statement. For example, to determine what string to substitute.
However, I am not able to understand the following points even after looking at the code.
a) What is the use ofngx_chain_update_chains? Replace_filter does not seem to use it. From what I understand, update chains should be called from each module to update the response body. However, replace filter does not seem to call it
b) The functionality of ngx_http_replace_split_chain is also not very clear
c) It would be great if there is some block level explanation of the replace filter code flow. If there is no documentation on this, will it be a good idea for me to document and put it up somewhere? Some pointers to start will obviously help
Thanks again for your work. Very helpful
On Wednesday, February 12, 2014 2:09:56 AM UTC+5:30, agentzh wrote:
Hello!
On Tue, Feb 11, 2014 at 10:09 AM, rohit.verma.email wrote:
> I was reading the Lua manual again and found
> that this can be achieved through Lua code in body_filter_by_lua section.
[...]
> There is a correctness issue of what happens when a chunk as a part of the
> string that is to be replaced. I’m wondering if there is a way to resolve
> that within body_filter_by_lua
>
Because ngx.re.gsub() is implemented upon PCRE, which is a
backtracking regex engine that can never handle chunk boundary
properly.
The ngx_replace_filter module uses my own sregex library which is a
true NFA-based implementation that never backtracks and supports
streaming matching:
https://github.com/agentzh/sregex
So you could write a Lua binding for the sregex library (using
LuaJIT's FFI, for example) and use it in the context of
body_filter_by_lua. But still you should still replicate the buffer
mangagement logic in ngx_replace_filter in Lua.
> Do you think that apart from the issue above, both these approaches are
> equivalent or is one to be preferred over the other? The criteria include
> performance and flexibility.
>
Streaming and strictly non-buffered regex substitutions are never an
easy topic :) That is why I created sregex and ngx_replace_filter in
the first place ;)
Eventually the sregex approach will get the best performance (with the
best balance between CPU usage and memory usage) for huge response
body data streams (assuming the semantics is sound).
BTW, the email address you used to send your last mail is not
subscribed to the list yet and posts from that address require manual
moderation. Please fix it on your side :) Thanks for your cooperation!
Regards,
-agentzh