openresty / replace-filter-nginx-module

Streaming regular expression replacement in response bodies
260 stars 68 forks source link

types setting not working #21

Open gumpjt opened 7 years ago

gumpjt commented 7 years ago

Hi there, I add this in my config, but when the response is text/html, it will also replace. Any comments?

replace_filter_types application/x-javascript javascript text/javascript application/javascript;

Thanks.

agentzh commented 7 years ago

@gumpjt This indeed looks like a problem in the implementation of the replace_filter_types directive. Will you mind creating a pull request to address this issue? Many thanks!

gumpjt commented 7 years ago

@agentzh I'm a newbie of C and Nginx. I'm willing to but I think it's out of my hand... 😭 I checked my config and I'm sure there is something wrong there.

agentzh commented 7 years ago

@gumpjt One workaround is to use ngx_lua's header_filter_by_lua* to conditionally set a custom nginx variable, say, $skip_replace, and then reference that variable in the replace_filter_skip directive:

https://github.com/openresty/replace-filter-nginx-module#replace_filter_skip

gumpjt commented 7 years ago

@agentzh Thanks.

I also found this method and I'm struggling about the order of header_filiter_by_lua*and thereplace_filter_skip directive. Now I need to make sure that header_filter_by_lua* should run before replace_filter_skip directive.

I'm using openresty, is there any way to change it? If I use pure Nginx, I can make the config options like this:

./configure --add-module=replace_module
--add-module=lua_nginx_module

Then the header_filter will handle first. But how to do it with openresty?

agentzh commented 7 years ago

@gumpjt Hmm, seems like we should add a new --prepend-module=PATH option to OpenResty's ./configure script so that the modules can be prepended to OpenResty's own --add-module=PATH options. Will you contribute a patch for this? Thanks!