Using replace filter inside a custom module
Hi,
This is not really an issue; more of a question about your code. I am building a custom module that needs to filter some parts of the response based on request cookies and the regex used depends on the cookie value. I am trying to use your code within my module for the regex based replacement but get rid of the configuration directives and set the regex and replacement string myself. But from looking at the code I am not exactly sure where the regex and replacement strings are being set. My first intuition is:
a) You are setting the value of the regex inside ngx_http_replace_filter_module.c:699 *re = value[1].data; b) You are setting the value of the replacement string inside ngx_http_replace_filter_module.c:710 ccv.value = &value[2];
Is this correct? I tried to run a simple test by hardcoding these two values but the replacement does not happen. Any clarification regarding this will be appreciated.
Thanks :-)
@divya84 It's not easy to summarize in a single sentence or two because it's complicated (yes, streaming processing has extra complication, especially in the context of streaming substitutions). I suggest you first take a look at
- the standard ngx_sub module: http://nginx.org/en/docs/http/ngx_http_sub_module.html The code structures of ngx_sub and ngx_replace_filter are similar but the former is definitely much simpler and easier to understand. The most complicated part in both of these two modules is buffer management.
- The implementation of the command-line utility,
sregex-cli, in the sregex project for basic usage of the sregex C API: https://github.com/openresty/sregex/blob/master/src/sre_cli.c
BTW, for such general discussions, you're recommended to join the openresty-en mailing list and post questions there instead. Please see http://openresty.org/#Community