Use of replace_filter in Lua code

24 views
Skip to first unread message

code_junkie

unread,
May 10, 2020, 12:15:38 AM5/10/20
to openresty-en

Hi,


1. I am running Lua code on Nginx server, and want to replace some text in the body response. But I don't want to expose the regex in conf file. So is there a workaround to add replace_filter inside content_by_lua_block or somewhere else in lua code?

Code in my conf file:


location
@test{
    content_by_lua_block
{
       
require("lua.code.path").content_by_lua()
   
}
    replace_filter
"search_term" "replace_term";
}


2. Also I want to use nginx context variables in both search and replace terms for the filter, is this possible?
Something like : replace_filter $var1 $var2;

I know this topic has been asked before on the forum, but still wanted to confirm again if there are any advancements on this.

Thanks in advance.


周俊

unread,
May 10, 2020, 12:51:02 AM5/10/20
to openre...@googlegroups.com
you can get from my code . github openstar body_filter …

code_junkie <giri...@gmail.com>于2020年5月10日 周日12:15写道:
--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openresty-en/602556b1-9d30-48f9-89b9-76ebed37f70d%40googlegroups.com.
Message has been deleted

code_junkie

unread,
May 11, 2020, 1:14:56 PM5/11/20
to openresty-en
Thanks for the response, but i see that you are using "ngx.re.gsub" which i believe doesn't work on streaming bodies and my problem is use of replace-filter-nginx-module (which has streaming bodies support via sregex library) in lua code.


On Saturday, May 9, 2020 at 9:51:02 PM UTC-7, 周俊 wrote:
you can get from my code . github openstar body_filter …
code_junkie <giri...@gmail.com>于2020年5月10日 周日12:15写道:

Hi,


1. I am running Lua code on Nginx server, and want to replace some text in the body response. But I don't want to expose the regex in conf file. So is there a workaround to add replace_filter inside content_by_lua_block or somewhere else in lua code?

Code in my conf file:


location
@test{
    content_by_lua_block
{
       
require("lua.code.path").content_by_lua()
   
}
    replace_filter
"search_term" "replace_term";
}


2. Also I want to use nginx context variables in both search and replace terms for the filter, is this possible?
Something like : replace_filter $var1 $var2;

I know this topic has been asked before on the forum, but still wanted to confirm again if there are any advancements on this.

Thanks in advance.


--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openre...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages