Hello agentzh,
Thanks for quick help.
One more thing I would like to know about replace_filter.
According to document, It works in location if context so I was trying to use it conditionally. In my configuration below code is not working.
location /replace_filter {
default_type 'text/html';
set $test '';
rewrite_by_lua 'ngx.var.test = 1 ' ;
echo "Hello world";
if ($test = '1') {
replace_filter 'Hello' 'Hi' gi;
}
if ($test = 2) {
replace_filter 'Hello' 'Hey' gi;
}
}
In above example replace_filter is not working as condition doesn't fall true. Is it so that rewrite_by_lua runs after nginx rewrite phase so in if condition variable doesn't get updated value from rewrite_by_lua* ?
Is there some way to achieve this?
Thanks,
Makailol
On Wednesday, April 2, 2014 1:15:00 AM UTC+5:30, agentzh wrote:
Hello!
On Tue, Apr 1, 2014 at 4:40 AM, Makailol Charls wrote:
> I have been using replace-filter-nginx-module to replace some text in
> response. I have been facing issues while matching \ (backward slash)
> character.
>
> Would you explain me,
> 1) How should single \ character be escaped?
> 2) How should \\ (double backward slashes) be escaped?
>
Well, it depends on NGINX's string literals' escaping rules in the
configuration file. The best way to find out is to test it via the
"return" directive (or ngx_echo module's "echo" directive). For
example,
location = /t {
return 200 "[\d \\d \\\\ \\]";
}
Accessing /t with curl gives
[\d \d \\ \]
When in doubt, just output your regexes.
Regards,
-agentzh